Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to save file in relative path using javascript

I want to save .json file in application path using javascript. I used the following code to save the file. but it saved in physical path. not in the application path. my code is:

 var fso = new ActiveXObject("Scripting.FileSystemObject");
 var s = fso.CreateTextFile("E:\\Model.json", true);
 s.WriteLine(json);
 s.Close();

in server side can use Server.MapPath but i dont know how to save in Javascript. please guide me friends, thanks in advance..

like image 784
ganesh Avatar asked Feb 15 '26 18:02

ganesh


1 Answers

I take it you're running this via Windows Scripting Host or similar.

Just use a relative path:

var s = fso.CreateTextFile("Model.json", true);

Note I left the E:\\ off.

I don't know what you mean by "the application path," but that will save the file in the current directory in which the script/application is running. If you want to do it relative to one of the "special" Windows folders, use FileSystemObject#GetSpecialFolder to get the special folder's path, then append your path to it.

like image 62
T.J. Crowder Avatar answered Feb 18 '26 07:02

T.J. Crowder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!