FileSystemObject sees unexisting files!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin Mrazek

    #1

    FileSystemObject sees unexisting files!

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

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

    fso = new ActiveXObject(" Scripting.FileS ystemObject");
    ts = fso.OpenTextFil e(pathN, ForWrite, true);
    ts.Write(conten t);
    ts.close();
    if (!fso.FileExist s(pathN)) {
    alert("The file <"+pathN+"> cannot be created.");
    } else {
    alert("Successf ully saved");
    }
    }


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

    What's wrong there ?

    Martin
  • Lee

    #2
    Re: FileSystemObjec t sees unexisting files!

    Martin Mrazek said:[color=blue]
    >
    >Hi,
    >I use FSO ActiveXObject to save file from IE. In JS like
    >
    >function saveToFile(path N, content){
    > var fso, ts;
    > var ForWrite = 2;
    >
    > fso = new ActiveXObject(" Scripting.FileS ystemObject");
    > ts = fso.OpenTextFil e(pathN, ForWrite, true);
    > ts.Write(conten t);
    > ts.close();
    > if (!fso.FileExist s(pathN)) {
    > alert("The file <"+pathN+"> cannot be created.");
    > } else {
    > alert("Successf ully saved");
    > }
    >}
    >
    >
    >surprisingly if the pathN contains unexisting path and the file is not
    >created, the fso.FileExists( pathN) still returns true (the message
    >"Successfull y saved" is written...).[/color]

    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\my Subfolder\myFil e.txt"

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

    Either use forward slashes or double the backslashes.

    Comment

    Working...