if (!app.project.file) { alert ("This project must be saved before running this script."); } else { var currFile = app.project.file; var currFileName = currFile.name; var extPos = currFileName.lastIndexOf("."); var ext = ""; if (extPos != -1) { ext = currFileName.substring(extPos, currFileName.length); currFileName = currFileName.substring(0, extPos); } var incrementer = 0; if (currFileName.charAt(currFileName.length -4) == "_") { //Assume the incrementer has run before if underscore is the fourth character from the end. //This is the case for files with 3 digit extensions. incrementer = currFileName.substring(currFileName.length - 3, currFileName.length); currFileName = currFileName.substring(0, currFileName.length -4); } incrementer++; var istring = incrementer + ""; if( (incrementer / 10) < 1.0) { istring = "0" + istring; } if( (incrementer / 100) < 1.0) { istring = "0" + istring; } var newFile = File(currFile.path + "/" + currFileName + "_" + istring + ext); alert(newFile.fsName); app.project.save(newFile); }