Skip to main content
Mr. Mendelli
Known Participant
October 25, 2018
Answered

How do I append a sub-directory in my save as script?

  • October 25, 2018
  • 1 reply
  • 791 views

I have a script I've made that saves images with a custom extension, currently it saves it as a copy in the source directory. I want to append a sub-directory for the copy to be saved in when it's complete. Here is my script:

#target photoshop

main();

function main(){

if(!documents.length) return;

try{

var Path= activeDocument.path;

}catch(e){var Path = "~/desktop";}

var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');

var saveFile= new File(Path + "/Maps" + Name + ".map.png");

sfwPNG24(saveFile);

}

function sfwPNG24(saveFile){

var pngOpts = new PNGSaveOptions;

pngOpts.compression = 9;

pngOpts.interlaced = true;

activeDocument.saveAs(saveFile, pngOpts, true, Extension.LOWERCASE);

}

I believe this is determined on line ten. I have already tried using `/Maps` but it does not work. Is this possible? If so, how can I get this to work in my script?

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

You actually have to create the sub folder first. Just adding the name to a path won't create it.

Declare the sub folder to a variable, then check to see if it exists. If not, add it.

var subFolder = new Folder(activeDocument.path + '/Maps/')

if (!subFolder.exists){subFolder.create()};

1 reply

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

You actually have to create the sub folder first. Just adding the name to a path won't create it.

Declare the sub folder to a variable, then check to see if it exists. If not, add it.

var subFolder = new Folder(activeDocument.path + '/Maps/')

if (!subFolder.exists){subFolder.create()};

Mr. Mendelli
Known Participant
October 26, 2018

That did the trick, thanks!