4 Replies Latest reply: Jul 26, 2012 8:39 AM by Pedro Cortez Marques RSS

    Copy all images from folder to global-folder when saving

    Pedro Cortez Marques Community Member

      I want to have a help here to do this:

       

      When I activate my saveCorrection script, I  use it to modify/correct a single image tha it is present on a folder of 5, 6 or 7 images).

      This means that I will have inside that folder 1 corrected images and also the other images I will need.

      To simplfy my daily upload work, I decided to avoid uploading each individual folder each time I make a correction. So I start saving each corrected image to a daily global folder on my desktop.

      At the ende of the day, I upload all my daily images I have corrected from that folder.

      This is done and works great but I need also to upload the other not corrected images from that global folder.

       

      For example:

       

      Folder1 has 6 images

      Folder2 has 5 images

      Folder3 has 6 images

      Folder4 has 4 images

       

      I correct image1 from Folder2

      and image4 of Folder4

       

      The global folder needs to have not only this 2 images but also needs to read all the present images from a folder that had a correction and pasting them to the global daily folder.

       

      At the end of the day I must have

      GlobalFolder with 9 images from Folders 2 and 4

       

      So I can I detect present files on a folder and passing them to another?

        • 1. Re: Copy all images from folder to global-folder when saving
          c.pfaffenbichler Community Member

          At the ende of the day, I upload all my daily images I have corrected from that folder.

          upload where?

          Could you possibly clarify your workflow with a chart or something?

          • 2. Re: Copy all images from folder to global-folder when saving
            Pedro Cortez Marques Community Member

            I only need to put all images together in a folder (anywhere).

             

            After that, the uploading process is a batch done automatically from another app outside photoshop.

             

             

            In less words, my question is:

             

            How can I detect how many images there are in a folder each time I save only one image there and then get all the files there and transfer (copy/paste) all images to another folder anywhere (that global folder).

            • 3. Re: Copy all images from folder to global-folder when saving
              c.pfaffenbichler Community Member

              I assume you are on Windows, so something like this

              // 2012, use it at your own risk;
              #target photoshop
              if (app.documents.length > 0) {
              var myDocument = app.activeDocument;
              var thePath = myDocument.path;
              var theFiles = Folder(thePath).getFiles(/\.(jpg|tif|eps|psd)$/i);
              alert (theFiles.join("\n"))
              };
              

              should get you the neighboring jps, tiffs, eps’, psds … amend the filter as needed.

               

              Then you can iterate through the array (Edit: with a for-function) and use the method

              File.copy (target: string)

              to copy them somewhere else.

              • 4. Re: Copy all images from folder to global-folder when saving
                Pedro Cortez Marques Community Member

                Thanks !

                 

                It helped me a lot simplifiing and finishing what I needed.

                I also manage to automatically create the date to name the daily folder.

                 

                 

                 

                #target photoshop
                if (app.documents.length > 0) {
                    var theDate = new Date();
                    var theYear = (theDate.getYear() + 1900).toString();
                    var mes = theDate.getMonth() + 1 ;
                    var theMonth = mes.toString();
                    if (theDate.getMonth() < 10) {
                    theMonth = "0" + theMonth;
                    }
                    var theDay = theDate.getDate().toString()
                    if (theDate.getDate() < 10) {
                        theDay = "0" + theDay;
                    }
                    theDate = theYear + "_" + theMonth + "_" + theDay;
                    //
                    var myDocument = app.activeDocument;
                    var thePath = myDocument.path;
                    var theFilesLength = Folder(thePath).getFiles(/\.(jpg)$/i).length;
                    var correctionsDayFolder =  Folder("~/Desktop/upload/" + theDate + "_Corrections"); 
                    if (!correctionsDayFolder.exists) correctionsDayFolder.create();
                    for (var u=0 ; u< theFilesLength ; u++) {
                        fileCorr = Folder(thePath).getFiles(/\.(jpg)$/i)[u]
                        var nameCorr = Folder(thePath).getFiles(/\.(jpg)$/i)[u].name
                        fileCorr.copy(correctionsDayFolder + "/" + nameCorr)
                        }
                };