469,623 Members | 1,422 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

FileSystemObject sees unexisting files!

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
Jul 23 '05 #1
1 1098
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.

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Marcelo Rizzo | last post: by
5 posts views Thread by John Dewbert | last post: by
reply views Thread by Daniel Lidström | last post: by
5 posts views Thread by Josh Rolfe | last post: by
2 posts views Thread by eric.goforth | last post: by
1 post views Thread by G Gerard | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.