Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exportDocument() 'destination folder does not exist' error

I'm trying to make a script in photoshop that will modify some layers and than export them as a PNG image. I've 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 export the active document of photoshop to the file specified by the saveFile parameter.

It's working fine with simple paths like "C:\images\result.png" but when trying with different paths like "~/Desktop/" or paths with some special characters the file isn't exported, and a "destination folder does not exist" error message appears.

Any idea how can I solve it?

like image 707
dvb Avatar asked Jan 20 '23 19:01

dvb


2 Answers

Well, I'm not sure why this is occur but you could 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'll export the file into a temporary file and then rename & move it to the requested path, should solve the path problem.

like image 112
B.D. Avatar answered Mar 11 '23 19:03

B.D.


exportDocument expects a full file name, not a folder path.

This works:

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

This doesn't work and gives the 'destination folder does not exist' error message:

activeDocument.exportDocument(new File("~/foo/"), ExportType.SAVEFORWEB, pngOpts);
like image 33
gregschlom Avatar answered Mar 11 '23 20:03

gregschlom