Skip to main content
Stephanie93
Participant
December 18, 2015
Answered

Help! Need script to automatically open files with the same name but in different location.

  • December 18, 2015
  • 1 reply
  • 1034 views

Good day friends,

So for my work, I need of a script to open files with the same name but located in a different folder. But since I'm a total noob when it comes to programming, I can't figure out how to do it. This is what I have in mind:

- I manually open an image.

- The script will search for a file with the same name in another folder that I specified.

- The script will then select the CMYK channel of the second file, and copy and paste it into the first file.

- The second file then is closed without saving.

I'm especially having trouble with the part where the script looks for a file with the same name as the file opened. I would be really grateful to get some help. Thanks in advance.

This topic has been closed for replies.
Correct answer c.pfaffenbichler

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var docName = myDocument.name;

try {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}

catch (e) {var basename = thedoc.name};

var thePath = /*insert folder path as string here*/+"/"+basename+/*insert file extension including period as a string here*/;

if (File(thePath).exists == true) {var otherDocument = app.open(File(thePath))};

};

1 reply

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
December 18, 2015

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var docName = myDocument.name;

try {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}

catch (e) {var basename = thedoc.name};

var thePath = /*insert folder path as string here*/+"/"+basename+/*insert file extension including period as a string here*/;

if (File(thePath).exists == true) {var otherDocument = app.open(File(thePath))};

};

Stephanie93
Participant
December 18, 2015

Worked flawlessly. Thank you sooooo much!!!

c.pfaffenbichler
Community Expert
Community Expert
December 18, 2015
- The script will then select the CMYK channel of the second file, and copy and paste it into the first file.

Copy/pasting might be wasteful, can’t you just duplicate the Layer over to the other file?