469,360 Members | 2,099 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,360 developers. It's quick & easy.

Unix path in Javascript

Hi,
I am new to Javascript and I developed a code and one of the functions needs a path (a directory location) as its input. It works fine for all windows paths
get _path("c:/somedir/somedir") but when i transfered this file on to a unix system and when I replace this path with a unix path it does not work. I am very sure I am giving the wrong path format. I tried all the possible ways, I am not sure what is missing.
Expand|Select|Wrap|Line Numbers
  1. get_path(".:/bin/somedir");
  2. get_path("/bin/somedir");
  3. get_path("./bin/somedir");
  4. get_path("\bin\somedir");
I tried all the above and non of them work. Please help me figure out the right path format.
Sep 9 '07 #1
9 2617
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

What does get_path do? Can you show the code for it?
Sep 10 '07 #2
Welcome to TSDN!

What does get_path do? Can you show the code for it?
Hi,
get_path() is just some sample name I used to identify a method. But any way my function is this

Expand|Select|Wrap|Line Numbers
  1. function ShowHomeFolderContents(){
  2.     var f = fs.GetFolder("C:/workspace");
  3. /* In unix var f= fs.GetFolder("/bin/out/test"); but this does not work */
  4.     var fc = new Enumerator(f.files);
  5.     var path = " ";                
  6.  
  7.     for (; !fc.atEnd(); fc.moveNext()) 
  8.     { 
  9.     //dispaly the folder names
  10.                 document.write(fc.item() )            
  11.     }     
  12. }
So it works fine for all windows path and not for unix path on an unix system. I am very sure its the path format.
Sep 10 '07 #3
acoder
16,027 Expert Mod 8TB
It seems like you're using ActiveX and not normal Javascript. ActiveX only works in Internet Explorer. That's probably what's causing the problem. Standard Javascript does not allow you to access the local file system.
Sep 10 '07 #4
It seems like you're using ActiveX and not normal Javascript. ActiveX only works in Internet Explorer. That's probably what's causing the problem. Standard Javascript does not allow you to access the local file system.
Thank you for your reply ..
I am really new and i am not sure, what you mean by using ActiveX and not Javascript and also why Javascript does not allow to access the local file system because it does allow me to access the windows file system.
Here is what I have
I have a .html file and a .js file. All my java functions are in the .js file. My .html call this .js file and it runs fine in windows when I write this function 'fs.GetFolder("C:/workspace");' But when i copied these files on to my other Unix machine and run the same .html (which calls the .js file) its just displays the html contents and not the output of the java functions. I am using alert statements to see the flow in my java code. And it stops at the same function with an unix path 'fs.GetFolder("/bin/opt/dir/");' So i am sure I am not using the correct unix path format.
Sep 10 '07 #5
acoder
16,027 Expert Mod 8TB
Post the rest of your code or a link.
Sep 10 '07 #6
Post the rest of your code or a link.
Ok, below is my Javascript file contents (file name: javaScript.js)

Expand|Select|Wrap|Line Numbers
  1. var fs = new ActiveXObject("Scripting.FileSystemObject");
  2. function ShowHomeFolderContents(){
  3.     var f = fs.GetFolder("C:/");
  4.     var fc = new Enumerator(f.files);
  5.     var path = " ";                
  6.  
  7.     for (; !fc.atEnd(); fc.moveNext()) 
  8.     { 
  9.     path = fc.item(); 
  10.     document.write(path+"<br>");                    }     
  11. }
  12.  
And below is my html (file name tree1.htm)

[HTML]<html>
<head>
<title>JavaScript Tree Control</title>
<style>
body {
font: 10pt Verdana, sans-serif;
color: navy;
}

.trigger {
cursor: pointer;
cursor: hand;
}

.branch {
display: none;
margin-left: 16px;
}
</style>
<script type="text/javascript" src="javaScript.js"></script>
</head>
<body>
<script type="text/javascript"> ShowHomeFolderContents()</script>
</body>
</html>[/HTML]

I want to copy this code to a unix machine and change the directory path in the function (var f = fs.GetFolder("C:/");) from C:/ to an unix directory path. And I am using IE to view the output. I just want to know how to substitute the dir path in unix. I hope you understand what I am trying to do.
Sep 10 '07 #7
acoder
16,027 Expert Mod 8TB
Have a look at the first line - it uses ActiveXObject. This is supported in IE only.

To prove this, download another browser such as Firefox, Opera, Netscape, etc. on Windows and try out your code. It won't work.
Sep 11 '07 #8
Have a look at the first line - it uses ActiveXObject. This is supported in IE only.

To prove this, download another browser such as Firefox, Opera, Netscape, etc. on Windows and try out your code. It won't work.
I Understand that it does not work with other browsers, but how will this help me with the unix path when I copy the Html and my JS files on to my unix server ?. Note: I will open with an IE on the client side.
OR do you mean to say that since it works only on IE, it will not work on the unix machine. But if thats the case then I am using IE on my client machine to view and run these files. Please help me solve my UNIX Path Problum.
Sep 11 '07 #9
acoder
16,027 Expert Mod 8TB
I Understand that it does not work with other browsers, but how will this help me with the unix path when I copy the Html and my JS files on to my unix server ?. Note: I will open with an IE on the client side.
OR do you mean to say that since it works only on IE, it will not work on the unix machine. But if thats the case then I am using IE on my client machine to view and run these files. Please help me solve my UNIX Path Problum.
This code will only work on IE. Unless you can somehow install IE in Unix, you can't get this code to work in Unix.
Sep 11 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by alanrn | last post: by
reply views Thread by =?Utf-8?B?QW5vbnltb3Vz?= | last post: by
6 posts views Thread by Marcin201 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.