FileSystemObject sees unexisting files!

M

Martin Mrazek

Hi,
I use FSO ActiveXObject to save file from IE. In JS like

function saveToFile(pathN, content){
var fso, ts;
var ForWrite = 2;

fso = new ActiveXObject("Scripting.FileSystemObject");
ts = fso_OpenTextFile(pathN, ForWrite, true);
ts.Write(content);
ts.close();
if (!fso.FileExists(pathN)) {
alert("The file <"+pathN+"> cannot be created.");
} else {
alert("Successfully saved");
}
}


surprisingly if the pathN contains unexisting path and the file is not
created, the fso.FileExists(pathN) still returns true (the message
"Successfully saved" is written...).

What's wrong there ?

Martin
 
L

Lee

Martin Mrazek said:
Hi,
I use FSO ActiveXObject to save file from IE. In JS like

function saveToFile(pathN, content){
var fso, ts;
var ForWrite = 2;

fso = new ActiveXObject("Scripting.FileSystemObject");
ts = fso_OpenTextFile(pathN, ForWrite, true);
ts.Write(content);
ts.close();
if (!fso.FileExists(pathN)) {
alert("The file <"+pathN+"> cannot be created.");
} else {
alert("Successfully saved");
}
}


surprisingly if the pathN contains unexisting path and the file is not
created, the fso.FileExists(pathN) still returns true (the message
"Successfully saved" is written...).

My first guess is that at some point you're specifying the value of
pathN as a string literal that contains single backslashes, such as:

"C:\myFolder\mySubfolder\myFile.txt"

Which would succeed in creating a file named
"myFoldermySubfoldermyFile.txt" in the current directory.

Either use forward slashes or double the backslashes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top