简体   繁体   中英

Renaming file using javascript in Adobe Pro

I would like to rename files, currently my files are named with only an employee ID but I want to rename the file to Resume_(ID) .

Example: from 12345 to Resume_12345 .

this.extractPages(0,0, "Resume_" +(this.documentFileName))

The above code works but it only saves and rename the first page of the file, meaning if the current file has 5 pages. I have tried to change the numbers in the script but the issue is that each file has a different numbers of pages.

How can I rename each page of the file instead of the first page?

Extract the pages to an array.

Then iterate the array of pages and do the renaming for all of them. Lets say you have an array "pageArray".

for(int i = 0; i < pageArray.length; i++){
   var oldFile = pageArray[i];  
   oldFile.rename ("NewName.txt");
}

This would iterate through all the pages and give them the same name. If you want different names you could do:

    for(int i = 0; i < pageArray.length; i++)
{
    let oldFile = pageArray[i];
        oldFile.rename ("NewName" + i);
}

Updated answer, now it would rename all the pages "NewName" + index number.

So it would be like: NewName0, NewName1, NewName2... all the way to the end of the array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM