2 Replies Latest reply on Aug 13, 2009 4:36 PM by BrianMcM

    [CS4] [JS] Can't figure out path names (Folder object)

    BrianMcM

      Hi.

       

      I have been reading documentation and posts and trying over and over but I can't figure out how the folder naming works when using the Folder object.

       

      In Windows Explorer, I will find a folder named, for example, "T:\Projects\2009".

       

      If I try the following in JavaScript, I am told that folder01 does not exist.

       

      var folder01 = Folder("T:\Projects\2009");

       

      However, if I use selectDialog and select the same folder, it does exist:

       

      var folder01 = Folder.selectDialog ("Select a folder");

       

      I don't know how to make it work when you want to supply a folder name as a string.

       

      Thanks.

        • 1. Re: [CS4] [JS] Can't figure out path names (Folder object)
          Thomas B. Nielsen Level 3

          Your problem is that \ is a special char in JS, that escapes the folowing character.

          So var folder01 = Folder("T:\Projects\2009");

          Should be var folder01 = Folder("T:\\Projects\\2009");// untested

           

          But i just do:

          var folder01 = Folder("T:/Projects/2009");

           

          Good luck

          • 2. Re: [CS4] [JS] Can't figure out path names (Folder object)
            BrianMcM Level 1

            Thank you , Thomas.

             

            I knew that it was something very basic that had just not registered. I have read about escape sequences in JavaScript but did not put it together with the folder names. When I go back to the first few pages of the File System Access chapter of the JavaScript Tools Guide it doesn't take too long to locate "On Windows, ... backslash is the escape character, so you must use a double backslash to indicate the character". It is easy when you know what you are looking for. When you don't, it all just makes your head spin.

             

            I guess this means that Windows and JavaScript are incompatible in this regard and that you have to edit any file or folder name that you grab from Windows before you can use it in a script.

             

            Thanks again,

             

            Brian