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

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

Explorer ,
Oct 25, 2018 Oct 25, 2018

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?

TOPICS
Actions and scripting
796
Translate
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 25, 2018 Oct 25, 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()};

Translate
Adobe
Community Expert ,
Oct 25, 2018 Oct 25, 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()};

Translate
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 ,
Oct 25, 2018 Oct 25, 2018
LATEST

That did the trick, thanks!

Translate
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