Error exportDocument () "Destination folder does not exist"

I am trying to create a script in Photoshop that will change some layers and export them as a PNG image. I copied the following code from another place:

function SavePNG(saveFile){ var pngOpts = new ExportOptionsSaveForWeb; pngOpts.format = SaveDocumentType.PNG pngOpts.PNG8 = false; pngOpts.transparency = true; pngOpts.interlaced = true; pngOpts.quality = 100; activeDocument.exportDocument(saveFile,ExportType.SAVEFORWEB,pngOpts); } 

The function exports the active Photoshop document to the file specified by the saveFile parameter.

It works fine with simple paths like "C: \ images \ result.png", but when you try to use different paths like "~ / Desktop /" or paths with some special characters, the file is not exported, but the "target" folder does not exist "error message appears.

Any idea how I can solve it?

+4
source share
3 answers

Well, I'm not sure why this is happening, but you can try the following modification:

 function SavePNG(saveFile){ var tmpFile = "./tmp.png"; tmpFile = new File(tmpFile); var pngOpts = new ExportOptionsSaveForWeb; pngOpts.format = SaveDocumentType.PNG pngOpts.PNG8 = false; pngOpts.transparency = true; pngOpts.interlaced = true; pngOpts.quality = 100; activeDocument.exportDocument(tmpFile,ExportType.SAVEFORWEB,pngOpts); tmpFile.rename (saveFile); tmpFile.changePath(saveFile); } 

it will export the file to a temporary file, and then rename and move it to the requested path, should solve the path problem.

+8
source

exportDocument expects the full file name, not the path to the folder.

It works:

 activeDocument.exportDocument(new File("~/foo/foo.png"), ExportType.SAVEFORWEB, pngOpts); 

This does not work and gives the error message "Destination folder does not exist":

 activeDocument.exportDocument(new File("~/foo/"), ExportType.SAVEFORWEB, pngOpts); 
+1
source

For people having this error and not using photoshop-script .

The error can be disabled in the target folder, but it happens because the folder that was used for the export phase is deleted. Therefore either

  • recreate the folder that was used during recording, or
  • recreate the export step
0
source

Source: https://habr.com/ru/post/1334099/


All Articles