19 Replies Latest reply: Sep 29, 2014 5:27 AM by brinkhelsinki RSS

    Move files from one folder to another javascript?

    timlogochair Community Member

      I am running a 3-action droplet automatically using windows task scheduler.  Here are the 3 steps:

      1.    Batch file to move files from hot folder to processing folder

      2.    Run IPP (dr brown's image processor pro) using preloaded settings to make several sizes copies of the files.

      3.    Bat file to move the files from processing folder to archive folder.

       

      The problem I am observing is that Step 1 works and IPP begins to run.  It only processes the first few images, and then moves on to the 3rd step where the bat file is ran to move all files from processing folder to archive folder.   The trouble is, only a few images were processes (about 10 or so), yet all of the images get moved to the archive without being processed.  Is there a way to make sure that step 2 (IPP) doesn’t begin until all files have successfully been moved from the hot folder to the processing folder?  IPP starts right away and files are still being transferred to the processing folder.

       

      Does anyone have a script that will move files from one folder to another? 

        • 1. Re: Move files from one folder to another javascript?
          DBarranca Community Member

          Hi,

          this might help:

           

          // Use at your own risk
          // test it before!
          var sourceFolder = new Folder("~/Desktop/temp/source");
          var destFolder = new Folder("~/Desktop/temp/destination");
          var fileList = sourceFolder.getFiles();
          for (var i = 0; i < fileList.length; i++) {
              if (fileList[i].copy(decodeURI(destFolder) + "/" + fileList[i].displayName)) {
                  fileList[i].remove();
              }  
          }
          

           

          Regards,

           

          Davide Barranca

          ---

          www.davidebarranca.com

          www.cs-extensions.com

          • 2. Re: Move files from one folder to another javascript?
            Muppet Mark Community Member

            This will create NEW files though...

            • 3. Re: Move files from one folder to another javascript?
              timlogochair Community Member

              Is there a way to do this without creating new files?

              • 4. Re: Move files from one folder to another javascript?
                DBarranca Community Member

                Not as far as I know, File methods in ExtendScript are documented on the JS Tools Guide, p. 51, and there's no move() alas.

                Does the date need to be the same of the original file? Because otherwise I see no problem in having files copied instead of moved.

                 

                Regards,

                 

                Davide Barranca

                ---

                www.davidebarranca.com

                www.cs-extensions.com

                • 5. Re: Move files from one folder to another javascript?
                  timlogochair Community Member

                  Yes, the dates are quite important for the archived files.  It will allow us to see quickly when the last edit was made to the original file since all the copies I'm making will have the new date.

                   

                  I'm wondering if there's anyway to introduce a delay of some sort in my droplet.exe between the bat file I have that moved files and when the image processor starts.

                  • 6. Re: Move files from one folder to another javascript?
                    Muppet Mark Community Member

                    There is nothing wrong with the new files but yes this can cause more back up than is really needed.

                    FRom a personal stand point I would have gone for Bridge for this workflow.

                    It has a move command that works propery.

                    It can watch a folder using a scheulled task.

                    I would have tried BridgeTalk to pass to PS for processing.

                    but that's just my preferred option...

                    • 7. Re: Move files from one folder to another javascript?
                      timlogochair Community Member

                      What is BridgeTalk?  Also, do you have an example of this that could help me?   Will I still be able to use the Image Processor Pro script/plugin in photoshop?

                      • 8. Re: Move files from one folder to another javascript?
                        Muppet Mark Community Member

                        It's in the guides but is the ExtendScript way to pass data between apps...

                         

                        Sent from my iPhone

                        • 9. Re: Move files from one folder to another javascript?
                          timlogochair Community Member

                          Do you, by chance, have an example of the move command that works?

                           

                          I assume I would just replace the bat file with the code you are proposing in my droplet.exe, right?

                          • 10. Re: Move files from one folder to another javascript?
                            JJMack Community Member

                            It sounds like that IPP and the move bat files are running concurrently that the bat starts some time after IPP starts and that it copies the files from the processing folder to the archive folder then delete the files in the processing folder before IPP has processed all the image files. Are you using widows scheduler to run a bat command file? I have not use a droplet to start Photoshop in years and don't understand what you mean by a three action droplet.  are you creating an droplet the use a single action that plays other actions?

                            Capture.jpg

                             

                             

                            The Process should be done is a single action that use two scripts steps so they are done in sequence not concurrently.

                            • 11. Re: Move files from one folder to another javascript?
                              timlogochair Community Member

                              I have a single action, that has three steps.  I've made this action into a droplet.exe

                               

                              1.  bat file to move files into processing folder

                              2.  IPP

                              3.  bat file to move file from processing to archive folder.

                               

                              The problem is that Step 2 begins shortly after step 1, and IPP only sees about 10 photos at the time IPP starts.  IPP processes those 10 completely, and then the 3rd batch file starts.  Step 3 never happens before IPP ends. 

                               

                              Here's what I'm going to try.

                              Step 1.  bat file to move files into processing folder

                              Step 2.  bat file to kill all open command windows.  not sure if the action will "wait" until the first step is finished or not..hmmm

                              Step 3.  IPP

                              Step 4.  bat file to move file from processing to archive folder.

                              • 12. Re: Move files from one folder to another javascript?
                                timlogochair Community Member

                                Result:  It does not wait to launch second bat file to "kill" all open command windows.  Keeps it clean, because only files copied are processed...but the major problem is that only a few images are moved/processed.

                                 

                                Is there a way to force a delay in the javascript that does the bat file?  Like if we tried to ping an invalid server and do it x number of times?

                                (See this thread:  How to sleep for 5 seconds in Windows's Command Prompt? (or DOS) - Stack Overflow)

                                 

                                Possible to do something similar to this in this in a photoshop javascript or action step?

                                 

                                Just need to introduce a pause for a pre-defined period of time into my action...somehow?  If I can do this, then I'll just "kill" the command windows before running the IPP.  I just need to specify a period of time (like 5 mins) for the files to copy before i kill the command window.

                                 

                                Any ideas?

                                • 13. Re: Move files from one folder to another javascript?
                                  timlogochair Community Member

                                  Wait.  I think this may work.

                                   

                                  Save a CMD/Bat file that will be run on a windows task scheduler.

                                   

                                  Cmd file will have these commands....

                                   

                                  1.  Move files from hot to processing folder. 

                                  2.  Run droplet.exe that has two steps in the action

                                       Step 1.  Run IPP

                                       Step 2.  JSX bat to move files from processing to archive.

                                   

                                  I think this will work...now to test.

                                  • 14. Re: Move files from one folder to another javascript?
                                    JJMack Community Member

                                    Please save the action set with the action is in and upload the .ATN file and post a link to the .atn file so we can actually see the Action.

                                    • 15. Re: Move files from one folder to another javascript?
                                      JJMack Community Member

                                      timlogochair wrote:

                                       

                                      Run droplet.exe that has two steps in the action

                                           Step 1.  Run IPP

                                           Step 2.  JSX bat to move files from processing to archive.

                                       

                                       

                                      That is what we talked about in the other thread thing need to run in sequence.  I don't know why you started a second thread I almost missed it.

                                      • 16. Re: Move files from one folder to another javascript?
                                        timlogochair Community Member

                                        Hi JJ,

                                        You posted over 10,000 lines of source code in the other thread, so it was nearly impossible to navigate .  This solution is now working perfectly.  The process starts with a windows task schedule calling a .bat file to do the following:

                                         

                                        1.  Move files from hot to processing folder. 

                                        2.  Run droplet.exe that has two steps in the action

                                             Step 1.  Run IPP

                                             Step 2.  JSX bat to move files from processing to archive.

                                         

                                        All is well.  Thanks so much for the help everyone.

                                        • 17. Re: Move files from one folder to another javascript?
                                          timlogochair Community Member

                                          Is there a way to add a step to my action to safely "close photoshop" after IPP finishes?  This will free up ram on my processing machine, when the script is not in use.

                                          • 18. Re: Move files from one folder to another javascript?
                                            JJMack Community Member

                                            I'm sure I have see a way to close down Photoshop in a Photoshop script.  I never had the need to.  It may be a simple statement like app.close(); I don't know javascript and only hack Photoshop script mostly by looking at others code.  app.close(); is a guess on my part. Let me try it. I was wrong its photoshop.quit();

                                             

                                            So make your MoveToArchive.jsx look something like this

                                             

                                            try{

                                               var BAT = new File(Folder.temp + "/MoveFilesToArchive.bat");

                                               BAT.open("w");

                                               BAT.writeln('Copy /Y "c:\\Process\\*.jpg" "c:\\Archive\\*.*"');

                                               BAT.writeln('Del "c:\Process\\*.jpg"');

                                               BAT.close();

                                               BAT.execute();   // execute the temp bat file

                                            }catch(e){

                                            alert("Bat MoveFilesToArchive  failed to execute.");

                                            };

                                            photoshop.quit();

                                            • 19. Re: Move files from one folder to another javascript?
                                              brinkhelsinki Community Member

                                              Hi!

                                               

                                              Thanks for the sample script. I'm trying to use it on a script I'm making for after effects (to easily change footage paths or to copy/move footage).

                                               

                                              I'm getting an error on the line

                                              var BAT = new File(Folder.temp + "/MoveFilesToArchive.bat");

                                               

                                              The error code is "Object of type Folder found where a Number, Array, or Property is needed."

                                               

                                              Edit:

                                              The script works fine if I use

                                              var BAT = new File(Folder.temp.toString() + "/MoveFilesToArchive.bat");
                                              
                                              

                                               

                                              Is there an easy way to change paths from relative to absolute? I need it to pick footage paths from the project view, as all the paths there are relative, but the .bat needs absolute paths.

                                               

                                              Edit: answering my own question fileobject.fsName gives you the absolute path.