• 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

Contributor ,
Oct 26, 2017 Oct 26, 2017

Copy link to clipboard

Copied

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

}

}

TOPICS
Actions and scripting

Views

1.4K

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

correct answers 1 Correct answer

Community Expert , Oct 26, 2017 Oct 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;

   

...

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 26, 2017 Oct 26, 2017

Copy link to clipboard

Copied

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 

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
Participant ,
Mar 05, 2022 Mar 05, 2022

Copy link to clipboard

Copied

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? 

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 ,
Mar 05, 2022 Mar 05, 2022

Copy link to clipboard

Copied

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.

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
Participant ,
Mar 07, 2022 Mar 07, 2022

Copy link to clipboard

Copied

Thank you Chuck!

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 06, 2022 Mar 06, 2022

Copy link to clipboard

Copied

Alternatively you may use: res = undefined

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
Participant ,
Mar 07, 2022 Mar 07, 2022

Copy link to clipboard

Copied

LATEST

Cheers Kukurykus!

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 ,
Oct 26, 2017 Oct 26, 2017

Copy link to clipboard

Copied

instead of this

var tempFile = File1; 
tempFile = tempFile.File1; 

use

var tempFile = File1.fullName;

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
Contributor ,
Oct 26, 2017 Oct 26, 2017

Copy link to clipboard

Copied

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.

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