5 Replies Latest reply on Apr 8, 2012 2:22 AM by Paul Riggott

    Photoshop javascript can't find a file from a given string, even though file is present.

    eronre

      Hi,

       

      So I have a script that opens up an array of files, performs a bunch of actions on them then saves them out.  I've been working on this script for years adding new features, but never had this issue until now.  When I run the script, it creates an array of new files with given paths.  The script then goes to open the files with a try statment, and 99% of the time the script continues on.  Now I'm getting an error saying the file can't be opened.  The file itself is on the machine, and it can be opened by Photoshop, as I can open it up manually.  So basically Photoshop can't seem to find the correct route based on the string I give it.  I have an alert that posts the string it tries to open and I've compared that to the location of the actual file and it's exactly the same.  When I restart the machine, this issue gets corrected, but then it seems to start again randomly.

       

      Has anyone else had this problem before, or maybe have an idea what's going on?

        • 1. Re: Photoshop javascript can't find a file from a given string, even though file is present.
          Paul Riggott Level 6

          Without seeing the code I can only guess.

          When opening files that are in an array I always use open(File(arrayName[index])); as this will make sure it is a file object and not just a string.

          • 2. Re: Photoshop javascript can't find a file from a given string, even though file is present.
            eronre Level 1

            Here's the piece of code that references the array and the opening.  I actually create an array of new files, then open those new files.  I guess I didn't say that in particular.

             

             

            function getFiles(sourceFolder) {

                                var fileArray = new Array()

                                var extRE = /\.(?:png|gif|jpg|bmp|tif|psd)$/i

                           var docs = [new File("/Users/user/Desktop/Orders/file_name")]

                                var len = docs.length

                                for (var i = 0; i < len; i++) {

                                          var doc = docs[i]

                                          if (doc instanceof File) {

                                                    var docName = doc.name

                                                    if (docName.match(extRE)) {

                                                              fileArray.push(doc)

                                                    }

                                          }

                                }

                                return fileArray

                      }

            for (var k = 0; k < fileArray.length; k++) {

                 try {

                      var doc = open(fileArray[k]

                 } catch (error) {

                      alert("The file at: " + fileArray[k])

                 }

            }

            • 3. Re: Photoshop javascript can't find a file from a given string, even though file is present.
              Paul Riggott Level 6

              I don't understand your code at all, you are not selecting any files at all?

               

              It should be something on the lines of ...

               

               

              var fileArray = sourceFolder.getFiles(/\.(png|gif|jpg|bmp|tif|psd)$/i);
              for(var k in fileArray){
                  try{
                      open(File(fileArray[k]));
                      }catch(e){ 
                          alert("The file at: " + fileArray[k]);
                          continue;
                          }
                 //do what ever ...
              }
              
              
              • 4. Re: Photoshop javascript can't find a file from a given string, even though file is present.
                eronre Level 1

                Hey Paul,

                 

                Sorry for the late response.  For the life of me I couldn't figure out how to log back in to this forum thing.  I log in at the top but I apparently didn't log in to the forum at the same time.  Missed the second log-in button.  Pretty backwards.

                 

                I left out a line or two from the code, basically moving from one function to the other.  What you have listed up above is pretty much what my code runs.  It's not really the code that I think is wrong, it's more that Photoshop loses track of the file system of the computer.  The script will work perfectly than all of a sudden it can't find a file.  I haven't been able to draw any connection to the script and the error I'm receiving.  It seems more like a Photoshop bug. 

                 

                From what I gathered from the operator who has been running in to this problem, she tends to restart Photoshop every time she runs this script.  I wonder if it's losing track of the local file system in the process of all the restarts.  The issue with finding the file is fixed every time that the computer is restarted, so it seems software related, not script related.  I told her not to restart the software so often and she didn't run to any issue last night.

                 

                Have you heard of any issue when Photoshop might lose track of the local file system?

                • 5. Re: Photoshop javascript can't find a file from a given string, even though file is present.
                  Paul Riggott Level 6

                  Sorry no, I can't think of any reason why it should do this.