locked
Filename length limit when using CreateTextFile and OpenTextFile RRS feed

  • Question

  •  

    Hello

    I have a script that creates a file and writes a value to it. When variable file_name is >259 characters, there would be a  "Path not found" error (e.description is that). As shown in the script below, I'm trying to create a file under deep folder tree. Each folder name is pretty long. Also 259 characters are not all file name or all folder name. It seems to me that this limit is quite short (I'm doing some engineering work). The file system does let you create a file in such a folder tree. How do I work around this? I think this might be a bug. How do I report this?

    I'm using Windows XP SP2. The error shows up in Windows Script Host 5.6 and 5.7.

    Thanks!


    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var file_name = "C:/a/b/c/d/file.txt";
    var out_value = 100;
    try {
           var ofh = fso.CreateTextFile(file_name, true);
           ofh.WriteLine(out_value);
           ofh.Close();
    } catch (e) {
           onError("Can not open '" + file_name + "' for writing -- " +
    e.description);
    }


    function onError(msg) {
           WScript.Echo(msg);
           WScript.Quit(-1);
    }
    Thursday, December 13, 2007 10:03 PM

Answers

  • Above code works fine me if I change file_name to

     

    Code Block

    var file_name = "C:\\a\\b\\c\\d\\file.txt";

     

     

    Regarding the file name limit, it is OS limitation (Windows Exploere doesn't allow either) and not the script engine's. As of now I don't have solution to this. Will update you if I get to know any.

     

    Might be useful http://support.microsoft.com/kb/894630

    Friday, December 14, 2007 7:26 AM

All replies

  • Above code works fine me if I change file_name to

     

    Code Block

    var file_name = "C:\\a\\b\\c\\d\\file.txt";

     

     

    Regarding the file name limit, it is OS limitation (Windows Exploere doesn't allow either) and not the script engine's. As of now I don't have solution to this. Will update you if I get to know any.

     

    Might be useful http://support.microsoft.com/kb/894630

    Friday, December 14, 2007 7:26 AM
  • You're right, Windows Explorer doesn't allow me. I didn't know about this OS limitation. Thanks!

    Friday, December 14, 2007 6:53 PM