Copy link to clipboard
Copied
Dear Forum members,
I had around 700 adobe illustrator files in (.eps format) which need to be renamed with new file name and to be saved back in same eps format , file renaming should be based on an input excel file that i recieved.
Can any help me with a java script code for easy completion of this task as renaming each and every file will take lot of time.
Attached screenshot for better understanding!
Copy link to clipboard
Copied
This should work, its not super refined, but it will do what you need.
I would suggest copying your files somewhere as a backup before making changes to them.
couple of things you will need to open the file and change.
var TopFolder = Folder("PATH TO FOLDER OF FILES")
var DataFile = File("PATH TO TABBED TEXT FILE")
/* alternatively, you can use a selection each time you run, just comment the lines above out and uncomment the ones below */
//var TopFolder = Folder.selectDialog("Pick the Folder containing the Files you want to rename")
//var DataFile = File.selectDialog("Pick the File containing the Data for renaming")
if(TopFolder!=undefined && DataFile!=undefined){
/*we open the data file and get the contents*/
DataFile.open('r');
DataFileContents = DataFile.read().split("\n"); /*split data on line returns*/
DataFile.close();
for(var a=0;a<DataFileContents.length;a++){
DataFileContents[a] = DataFileContents[a].split("\t") /*split rows on tabs*/
}
var allFiles = scanSubFolders(TopFolder); /*get all of the files in the TopFolder*/
var afL = allFiles.length;
for (var i=0;i<afL;i++){
var ThisFile = allFiles[i]
var ThisFileName = ThisFile.name.toString().substring(0,ThisFile.name.toString().lastIndexOf(".")) /*pull only the filename back and cut off the end*/
var NewName = FindDataInArray(ThisFileName,DataFileContents)+".eps" /*get the new name and add .eps to it*/
if(NewName!=false){
ThisFile.rename(NewName);
}
}
}
/*this is not the best function, but it works
this function assumes the data is set up so the old file name is array 0 and new name is array 1
*/
function FindDataInArray(DataToFind,ArrayToTest){
for(var a=0;a<ArrayToTest.length;a++){
if(ArrayToTest[a][0]==DataToFind) return ArrayToTest[a][1]
}
return false
}
function scanSubFolders(tFolder) { // folder object
var sFolders = new Array();
var allFiles = new Array();
sFolders.push(tFolder);
for (var j = 0; j < sFolders.length; j++) { // loop through folders
var procFiles = sFolders[j].getFiles();
for (var i = 0; i < procFiles.length; i++) { // loop through this folder contents
if (procFiles[i] instanceof File) {
allFiles.push(procFiles[i]);// if no search mask collect all files
} else if (procFiles[i] instanceof Folder) {
sFolders.push(procFiles[i]);// store the subfolder
scanSubFolders(procFiles[i]);// search the subfolder
}
}
}
return allFiles;
};
Copy link to clipboard
Copied
Hello Rob, thank you very much for sharing the above code here,
I followed the above steps i got below errors, can you please help
Copy link to clipboard
Copied
Cant see the top lines, but if TopFolder is undefined or in the wrong format, then it will fail.
Copy link to clipboard
Copied
Rob, thank you very much for sharing the above code here,
I followed the above steps i got below errors, can you please help