• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Move files from one folder to another javascript?

Explorer ,
Aug 03, 2014 Aug 03, 2014

Copy link to clipboard

Copied

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? 

TOPICS
Actions and scripting

Views

35.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Advocate ,
Aug 03, 2014 Aug 03, 2014

Copy link to clipboard

Copied

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.copy(decodeURI(destFolder) + "/" + fileList.displayName)) {

        fileList.remove();

    } 

}

Regards,

Davide Barranca

---

www.davidebarranca.com

www.cs-extensions.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 03, 2014 Aug 03, 2014

Copy link to clipboard

Copied

This will create NEW files though...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 03, 2014 Aug 03, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 04, 2014 Aug 04, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2014 Aug 04, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 04, 2014 Aug 04, 2014

Copy link to clipboard

Copied

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2014 Aug 04, 2014

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 04, 2014 Aug 04, 2014

Copy link to clipboard

Copied

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

Sent from my iPhone

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2014 Aug 04, 2014

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2018 Mar 14, 2018

Copy link to clipboard

Copied

Offtopic / What is difference between .name and .displayName (take a look at reply 1)

JavaScript Tools Guide say:

displayName (String): The localized name of the referenced file, without the path. Read only.

name (String): The file name portion of the absolute URI for the referenced file, without the path specification. Read only.

Where is difference in using them - can someone give me any example with different results?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 15, 2018 Mar 15, 2018

Copy link to clipboard

Copied

var file = new File("C:\\A1\\Вася.txt");

alert( file.displayName + " " + file.name)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 15, 2018 Mar 15, 2018

Copy link to clipboard

Copied

LATEST

I saw it was decoded, but wasn't sure it's what .displayName doing as all letters were written in english THX!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2014 Aug 04, 2014

Copy link to clipboard

Copied

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.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 05, 2014 Aug 05, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 05, 2014 Aug 05, 2014

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 05, 2014 Aug 05, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2014 Aug 05, 2014

Copy link to clipboard

Copied

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.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 05, 2014 Aug 05, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 07, 2014 Aug 07, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 07, 2014 Aug 07, 2014

Copy link to clipboard

Copied

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();

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 29, 2014 Sep 29, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2014 Aug 05, 2014

Copy link to clipboard

Copied

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.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines