Copy link to clipboard
Copied
I've written the following script to iterate through a hierarchy of directories (using some code on this forum), then it opens any PDF files and resaves them without any downsampling. It works great, except when it's run for a while it has two issues:
1) It always seems to crap out after about 1400 files processed, it simply errors out in the code somewhere which has worked fine in the previous 1399 files. If I restart, it works fine again - this seems to happen with every photoshop script I've worked on (I usually have to process over 50,000 files in a batch, so I just have to keep rerunning things over and over), I don't know if there is a memory leak or something, but at some point during a run of a lot of files (usually after 1400 openings or so), something simply fails.
2) My main problem right now is that after a running this on about 8100 files (in 4 different sessions), the script has simply stopped working, giving me the error message:
ReferenceError: open is not a function
Now, as I said, this script has worked perfectly for two days (other than issue #1), and it seems to do this no matter what the input file is. This happened once yesterday and it just seems like after a day it started working again today until it failed again. Has anyone experienced this before and have a solution? I have no idea why this would suddenly change when the code hasn't:
var topFolder = new Folder('//192.168.0.25/Assets');
var fileandfolderAr = scanSubFolders(topFolder,/\.(pdf)$/i);
function getPDFSaveOptions()
{
var pdfOpts = new PDFSaveOptions();
pdfOpts.downSample = PDFResample.NONE;
pdfOpts.generateThumbnails = true;
pdfOpts.preserveEditability = true;
return pdfOpts;
}
function scanSubFolders(tFolder, mask) { // folder object, RegExp or string
var sFolders = new Array();
var allFiles = new Array();
sFolders[0] = tFolder;
for (var j = 0; j < sFolders.length; j++){ // loop through folders
var procFiles = sFolders
for (var i=0;i<procFiles.length;i++){ // loop through this folder contents
if (procFiles instanceof File ){
//if(mask==undefined) allFiles.push(procFiles);// if no search mask collect all files
if (procFiles.fullName.search(mask) != -1)
{
$.writeln(fileIndex + " " + procFiles);
try
{
var docRef = open(procFiles); <----- FAILS HERE
docRef.saveAs(new File(docRef.fullName), getPDFSaveOptions(), false, Extension.LOWERCASE);
docRef.close();
}
catch(e){ alert(e); }
fileIndex++;
}
}else if (procFiles instanceof Folder){
sFolders.push(procFiles);// store the subfolder
scanSubFolders(procFiles, mask);// search the subfolder
}
}
}
return [allFiles,sFolders];
};
Copy link to clipboard
Copied
Looks like there was a name clash somewhere, adding the following to the top seemed to fix issue #2:
#target photoshop
Still wondering what causes #1 though!
Copy link to clipboard
Copied
What kind of file does it fail on. I do not see any file filtering being done. Is it a file type supported by Photoshop that is failing to open. I see your processing .PDF files but the getFiles does not look to me like it is filtering just pdf but I do not know Javascript I just hack