Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write to a local file using a relative path

Status
Not open for further replies.

AndyCLee

Technical User
Mar 10, 2003
49
GB
Hi,

I have managed to write to a local file using the following javascript:

Code:
fso = new ActiveXObject("Scripting.FileSystemObject");
s = fso.OpenTextFile("C:\\test.txt", 2, 1, -2);
s.writeline("This is a test");
s.Close();

But I would like to make the path relative. I have tried changing the path to "../test.txt" but this didn't work.

I then investigated using the MapPath method, but this only appears to work on a server "Server.MapPath".

Has anyone got any suggestions how I can do this?

Thanks

Andy
 
>> have tried changing the path to "../test.txt"

relative path works with the folder of the file that calls it as its destination

so if u call a ../ in an HTML file it will look for a file one folder above (on the server). locally we dont know where the HTML files are saved so ../ will NOT work...

Known is handfull, Unknown is worldfull
 
ok, that explains why the ../ didn't work then. Although I thought it would have gone 1 folder up from either the .js file or the .htm file that called the function.

Thanks anyway vbkris - anyone else know how to do this?
 
>I have tried changing the path to "../test.txt" but this didn't work.
It still works, only that you didn't know where it is.

Add a line of alert so that you know.
[tt] alert(fso.getfolder("../").path);
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top