Hello
I have a problem, I'm trying to save all open documents as PNG
but I want them in a new folder.
the opened documents come from a PDF multi pages, it means that the files are not yet saved.
So I figured that I can take the path of the latest opened file (the PDF) and I want to modify the extension of this string to create my new folder.
the problem is that it tell me that the function replace or slice doesn't exist!?
why?
thanks for any help
Code: Select all///////////////////////////////////////////////////////////////////////////////
// saveToPNGAndCloseAllDocuments - save all documents to PNG and close them and quit application
///////////////////////////////////////////////////////////////////////////////
function savePNGAndCloseAllDocuments() {
var test = documents.parent.recentFiles[0];//.replace(/\.[^\.]+$/, '');
alert(test); // just a popup debug. it should be something like that --> "~/Documents/TEST/01_03Photoshop.pdf"
var Path = test.slice(0, -4);
var SavePath = Path; // it should be something like that --> "~/Documents/TEST/01_03Photoshop"
//Folder to create on the desktop
var folder1 = Folder(SavePath);
//Check if it exist, if not create it.
if(!folder1.exists) folder1.create();
var Name = "";
while (documents.length > 0) {
Name = activeDocument.name.replace(/\.[^\.]+$/, '');
var saveFile = File(SavePath + "/" + Name + ".png");
if(saveFile.exists) saveFile.remove();
SavePNG(saveFile);
// no need to save when closing because we already saved the PNG
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
photoshop.quit();
}
function SavePNG(saveFile){
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.embedColorProfile = true;
pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
pngSaveOptions.matte = MatteType.NONE;
pngSaveOptions.quality = 1;
pngSaveOptions.PNG8 = false; //24 bit PNG
pngSaveOptions.transparency = true;
activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE, DialogModes.NO);
}
Error when modifying path string
-
pfaffenbichler
Error when modifying path string
slice and replace are methods for Strings, not Files.
Does this work?
Code: Select allvar Path = test.fullName.slice(0, -4);
Does this work?
Code: Select allvar Path = test.fullName.slice(0, -4);