Re: file path issue
reverendlinux <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.xpfe |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <[email protected]> |
On Mar 23, 2:47 am, Shibu Narayanan <[email protected]> wrote: > I have a file path saved in a text configuration file. I am not able to create the file. If I hard code the file path, it works. > > I have tried to give the file path as "C:\\myDir\\New.txt" as well as with single backslash "C:\myDir\New.txt". > > Code below.. > > var filePath1 =''; > > //this works > > filePath1 = "C:\\myDir\\New.txt"; > > writeToFile(filePath1, "Hello World"); > > //this does not work > > filePath1 = getfilePath1(); //the filepath URL is read from a text file > > writeToFile(filePath1, "Hello World"); From my own experience, this is how I would create a new file when the file name is not static: var filePath1 = getfilePath1(); // full path & file name; ie - C:\ \myDir\\New.txt var file = Components.classes["@mozilla.org/file/local; 1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath( filePath1 ); file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 ); Other more skilled folks here can probably tweak this a bit, but this snippett has worked for me.