11 Replies Latest reply on Jul 31, 2013 9:14 AM by Michael L Hale

    Folder Modification

    maximeleve Level 1

      Hello, (it's me again, sorry ...)


      I finally made a script that makes me happy but I have a weird phenomeon with folders, more especially with files in folders.

      In my script, I ask the user to select a folder with image files inside (jpg, png, etc...) it works. One time, two times, etc...


      Then, If for example, I delete a file in the folder used by the user. The script won't work..... No error.

      I tried to close/open PS but nothing....


      I don't understand... Do I need to do something for the folder at the end of my script ??


      PS : I am on Mac OS Mountain Lion. I can't try on WIN for now...


      Best regards,



        • 1. Re: Folder Modification
          Michael L Hale Level 5

          I have never run into that problem when deleting files( either with a script or with the OS ). So unless it is a Mac OS issue I would say there is something wrong with your script.

          • 2. Re: Folder Modification
            maximeleve Level 1

            Thks... I will re-check everything.

            Thank you anyway.

            • 3. Re: Folder Modification
              Michael L Hale Level 5

              If you are willing to post your script we might be able to spot if there is an error in the script. Hard to say without seeing the code.


              if posted, at the least I could test it on Windows to help determine where the problem occurs.

              • 4. Re: Folder Modification
                maximeleve Level 1

                Hello Michael,


                Thks again for your help.

                I will try to post it but it is quite long... Can I send it directly to you as private message ?


                I actually made some progress.

                On mac OS, as soon as I removed a file in my working folder. I get :


                Error: Cannot open the file because the open options are incorrect"

                -> var document = open(fileList[0]);


                I tried to modified var document = open(fileList[0]); to var document = open(fileList[1]);

                Then it works....(it fails somewhere else because of the same issue but ...)

                I will try on Win today and Keep you noticed.



                • 5. Re: Folder Modification
                  maximeleve Level 1



                  It  actually runs on win7.... Hum.

                  I take a folder, remove 1 file or several, and it works...


                  One thing I noticed, with the same folder (copy/paste on win7) that failed after I removed files on Mac OS, It

                  fails one win7.

                  Euh..... Some kind of indexing problem due to Mac OS ??

                  • 6. Re: Folder Modification
                    Michael L Hale Level 5

                    ... Some kind of indexing problem due to Mac OS ??

                    No, from the error message it looks like you are trying to open a file that is not an image. If fileList[0] points to a missing or otherwise invalid file you would get a different error.  How are you creating the fileList array? You should be able to reduce your code to something small enough to post that still has that error. We don't need to see the full script. Just the part that gets and tries to open the files from the folder.

                    • 7. Re: Folder Modification
                      maximeleve Level 1

                      Thks again for your help and I am really sorry for the misunderstood about 'correct Answer'.

                      So I tried to reduce the script the get the minimal about doc manipulation.



                      inputFolder = Folder.selectDialog('Select the folder');


                      //Save the new file avec JPEG
                      var jpegOptions = new JPEGSaveOptions();
                      // List of the files
                      var fileList = inputFolder.getFiles();
                      // number of documents
                      var doc = fileList.length;
                      //get a reference to the new document
                      var document = open(fileList[0]);
                      app.activeDocument = document;
                      docwidth = app.activeDocument.width;        // width of the current A
                      docheight = app.activeDocument.height;    // height of the current A
                      // Create a new document
                      var newdoc = app.documents.add(newwidth,newheight,300,'Panel');
                      app.activeDocument = document;
                          for(var j = 0 ; j<=fileList.length; j++)
                                  document = open(fileList[docnumb]);
                                      app.activeDocument = newdoc;
                                  var setRegion = Array(
                      • 8. Re: Folder Modification
                        Michael L Hale Level 5

                        The line

                        var fileList = inputFolder.getFiles();

                        gets all the files in a folder, including non image files.

                        The line

                        var document = open(fileList[0]);

                        tries to open the first file in the folder without checking that it is an image file.

                        Later you have the line

                        document = open(fileList[docnumb]);

                        that is still trying to open a file without making sure it's an image file.


                        You should either use a mask in getFiles or check the file before opening.


                        I understand on Mac every file has a matching file that start with "._" It could be your scirpt is tring to open one of those files. That would also explain why when you copied the folder to Windows you had the same problem. Those ._ files were copied as well. Those type files may not be the problem but I still think it is because you are trying to open a file that Photoshop doesn't know how to parse.

                        • 9. Re: Folder Modification
                          Michael L Hale Level 5

                          Try adding the line


                          before the open(fileList[0]) line to make sure the file is the one you expected.

                          1 person found this helpful
                          • 10. Re: Folder Modification
                            maximeleve Level 1



                            You are definilty very very good.

                            It tries to open   something .DS_Store "~/Desktop/Picture Ref 2/.DS_Store" which of course doesn't exist on WIN.


                            I put a filter on getFiles and it works.....


                            Thks a lot again.


                            PS : I selected the good author this time

                            • 11. Re: Folder Modification
                              Michael L Hale Level 5

                              Glad it is working. I almost always use a mask/filter with getFiles for that reason. Windows doesn't noramlly have those type of Mac files but non-image format files are a problem on both OS.