Hello everyone, I have a huge amount of psd files. Some of them are corrupted and can't be opened. I've created this script to: 1. try and open each one of them, if I can open the file then: > write it to log > move the file to a new folder (t stands for "try was executed") else (if file can't be opened and is corrupted): > log it to file the problem that i'm facing is that I have one kind of error that still pop ups even when I've used try and catch: I am still getting the error: "ignore read composite data" #target photoshop var theFolder = Folder.selectDialog("select folder"); var fileandfolderAr = scanSubFolders(theFolder,/\.(psd)$/i); //var fileandfolderAr = scanSubFolders(topFolder,/\.(jpg|tif|psd|bmp|gif|png|)$/i); var fileList = fileandfolderAr[0]; var fromFolder = theFolder.fsName + '\\'; var t = theFolder.fsName + '\\t\\'; for(var a = 0 ;a < fileList.length; a++) { var Name = fileList.name; try { open(fileList); opened_log(); app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); moveFile(fromFolder,Name,t,Name) } catch(e) { error_log(); } } 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 .getFiles(); 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) allFiles.push(procFiles); // otherwise only those that match mask }else if (procFiles instanceof Folder){ sFolders.push(procFiles);// store the subfolder scanSubFolders(procFiles, mask);// search the subfolder } } } return [allFiles,sFolders]; }; function moveFile(fromFolder,fileName,toFolder,newName) { retcode = false; if(!(new Folder(toFolder)).exists){ new Folder(toFolder).create();} if(!(new Folder(toFolder)).exists){ alert("Folder " + toFolder + " could not be created.");} else { if (new File(fromFolder + fileName).exists){ //if (app.systemInformation.indexOf("Operating System: Windows") >= 0) app.system('Move /Y "' + fromFolder + fileName + '" "' + toFolder + newName + '"' ); //will overwrite with /Y without prompt for (var i=0;i<100000;i++) { if (!(new File(fromFolder + fileName).exists)) break; } //give it some time if (newName=="") {newName = fileName;} if (!(new File(fromFolder + fileName).exists) && (new File(toFolder + newName).exists)) retcode = true; } else {alert("File " + fromFolder + fileName + " does not exists");} } return retcode; } function error_log() { if(documents.length) { var doc = activeDocument; var a,b,c,d =""; // Name without file extension var Name = doc.name; if (Name.indexOf(".") != -1 ) Name=Name.substr(0,Name.lastIndexOf(".")); // var log = File(Folder.desktop + "/" + "error log.csv"); //var log = File(Folder.desktop + "/" + Name + ".csv"); log.open("a"); a=decodeURI(doc.name); //b=decodeURI(doc.path.fsName); var today = new Date(); var todayDay = today.getDate(); if (todayDay < 10) { todayDay = "0" + todayDay; } var todayMonth = today.getMonth()+1; if (todayMonth < 10) { todayMonth = "0" + todayMonth; } var todayYear = today.getFullYear(); var todayDate = todayDay+'-'+todayMonth+'-'+todayYear; var todayTime = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); var todayDate_Time = todayDate + " " + todayTime; log.writeln(todayDate_Time + "," + a); log.close(); } } function opened_log() { if(documents.length) { var doc = activeDocument; var a,b,c,d =""; // Name without file extension var Name = doc.name; if (Name.indexOf(".") != -1 ) Name=Name.substr(0,Name.lastIndexOf(".")); // var log = File(Folder.desktop + "/" + "opened log.csv"); //var log = File(Folder.desktop + "/" + Name + ".csv"); log.open("a"); a=decodeURI(doc.name); b=decodeURI(doc.path.fsName); var today = new Date(); var todayDay = today.getDate(); if (todayDay < 10) { todayDay = "0" + todayDay; } var todayMonth = today.getMonth()+1; if (todayMonth < 10) { todayMonth = "0" + todayMonth; } var todayYear = today.getFullYear(); var todayDate = todayDay+'-'+todayMonth+'-'+todayYear; var todayTime = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); var todayDate_Time = todayDate + " " + todayTime; log.writeln(todayDate_Time + "," + a +"," + b); log.close(); } }
... View more