#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    2
    Rep Power
    0

    Question Need help finding the current directory in JavaScript


    I am making a hypertext application (hta) that will be downloaded and put into who-knows-what directory by the user.
    I want to output a text file to whatever directory they put the hta into. But how can I get the directory path?

    This is what I am trying to do:
    Code:
    function Save()
    {
        fso = new ActiveXObject("Scripting.FileSystemObject");
        ts = fso.CreateTextFile("*current directory*", true);
    
        //do stuff; save stuff
    
        ts.Close();
    }
    I can specify the path name and it works, but that is useless for what I am trying to do.

    Things I have tried:

    1) Simply naming the file: ts=fso.CreateTextFile("output.txt",true)

    2) using document.location.pathname
    This returns the path of the .hta file, so I use replace("myhta.hta","output.txt");
    But then I get a path not found error.

    This has to be simple, but I can't get it. Thanks for any help you can give.

    Frustrated in New Orleans
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    2
    Rep Power
    0
    I got it:

    Code:
    function getCurrentDirectory()
    {
        var fso=new ActiveXObject("Scripting.FileSystemObject");
        path = unescape(document.location); //replace %20 with " ", etc.
        path = path.substring(8,path.lastIndexOf("/")+1); //chop off "file:///" and file name
    
        return path;
    }
    Thanks anyway.

IMN logo majestic logo threadwatch logo seochat tools logo