Skip to main content
Known Participant
October 26, 2017
Answered

Move files

  • October 26, 2017
  • 3 replies
  • 2001 views

Hi friends! I need help getting a working script to create and move the open document to a sub folder called "Processed Image" I have this script but the current document has not been moved to the sub folder. Where is the error? Thank you

#target photoshop

app.bringToFront();

var docRef = app.activeDocument;

var sourceFolder = app.activeDocument.path ;

var File1 = docRef;

var tempFile = File1;

tempFile = tempFile.File1;

var outputFolder = new Folder(File1.path + "/Processed Image"); // defines the name of the subfolder

//Check if it exist, if not create it.

if(!outputFolder.exists) outputFolder.create(); //if subfolder not exist then create

if(tempFile != null){

var saveName = tempFile.name;

var res = tempFile.copy(new File(outputFolder+'/'+saveName));

if(res != true) throw('Unable to move file to '+decodeURI(backupFolder));

res = tempFile.copy(new File(outputFolder+'/'+saveName));

if(res != true){

throw('Unabe to move file to '+decodeURI(outputFolder));

}else{

// if we get here then the file has been backuped and moved to new folder so delete

tempFile.remove();

app.open(new File(outputFolder+'/'+saveName));// open moved file to work on

}

}

This topic has been closed for replies.
Correct answer Chuck Uebele

Try this:

#target photoshop 

app.bringToFront(); 

var docRef = app.activeDocument; 

var sourceFolder = app.activeDocument.path ; 

var res

 

var File1 = docRef; 

var outputFolder = new Folder(File1.path + "/Processed Image"); // defines the name of the subfolder 

var tempFile = new File(docRef.path +'/'+docRef.name)

//Check if it exist, if not create it. 

if(!outputFolder.exists) outputFolder.create(); //if subfolder not exist then create 

if(tempFile.exists){ 

    var saveName = tempFile.name;

    tempFile.copy(outputFolder+'/'+saveName); 

    res = new File(outputFolder+'/'+saveName)

if(!res.exists) {throw('Unable to move file to '+decodeURI(outputFolder));

}

else{ 

    // if we get here then the file has been backuped and moved to new folder so delete 

    tempFile.remove(); 

    app.open(res);// open moved file to work on 

3 replies

Ps-DesignAuthor
Known Participant
October 26, 2017

It works divinely well! I tested the modification made by Chuck Uebele and the suggestion of the r-bin and both worked perfectly. Many thanks to both friends.

Legend
October 26, 2017

instead of this

var tempFile = File1; 
tempFile = tempFile.File1; 

use

var tempFile = File1.fullName;

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
October 26, 2017

Try this:

#target photoshop 

app.bringToFront(); 

var docRef = app.activeDocument; 

var sourceFolder = app.activeDocument.path ; 

var res

 

var File1 = docRef; 

var outputFolder = new Folder(File1.path + "/Processed Image"); // defines the name of the subfolder 

var tempFile = new File(docRef.path +'/'+docRef.name)

//Check if it exist, if not create it. 

if(!outputFolder.exists) outputFolder.create(); //if subfolder not exist then create 

if(tempFile.exists){ 

    var saveName = tempFile.name;

    tempFile.copy(outputFolder+'/'+saveName); 

    res = new File(outputFolder+'/'+saveName)

if(!res.exists) {throw('Unable to move file to '+decodeURI(outputFolder));

}

else{ 

    // if we get here then the file has been backuped and moved to new folder so delete 

    tempFile.remove(); 

    app.open(res);// open moved file to work on 

Known Participant
March 6, 2022

I have a question regarding the line 

var res

It seems to work fine but I was wondering, don't you have to at least put something after the variable like 

var res = "" 

Is is good enought to declare a variable as simply a name as shown here? 

Known Participant
March 7, 2022

No, you don't need to put anything. That can be done later, when you actually have something to assign the variable. You can do that if you want to define what type of variable it is, like string, boolean, array, etc.


Thank you Chuck!