Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
2

Need java script in renaming multiple illustrator file names

Community Beginner ,
Apr 02, 2024 Apr 02, 2024

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!Capture.JPGexpand imageCapture1.JPGexpand image

 

 

TOPICS
Experiment , Feature request , How-to , Import and export , Scripting , SDK , Tools , Type
437
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Participant ,
Apr 02, 2024 Apr 02, 2024

This should work, its not super refined, but it will do what you need.

  1. run the file from illustrator (or indesign)
  2. select a folder containing the files you want to rename
  3. select a file containing the data of old name and new name. data must be saved as a tabbed text file with column 1 being old name and column 2 being new name
  4. assumes all of the files will be .eps

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;
};

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 03, 2024 Apr 03, 2024

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

 

Venkateswarul31426244qf9j_0-1712158281170.pngexpand image

Venkateswarul31426244qf9j_1-1712158310707.pngexpand image

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 03, 2024 Apr 03, 2024

Cant see the top lines, but if TopFolder is undefined or in the wrong format, then it will fail. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 03, 2024 Apr 03, 2024
LATEST

 Rob, thank you very much for sharing the above code here, 

I followed the above steps i got below errors, can you please help

 

Venkateswarul31426244qf9j_0-1712158281170.pngexpand image

Venkateswarul31426244qf9j_1-1712158310707.pngexpand image

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines