简体   繁体   English

在Adobe Pro中使用javascript重命名文件

[英]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) . 我想重命名文件,目前我的文件只用一个员工ID命名,但我想将文件重命名为Resume_(ID)

Example: from 12345 to Resume_12345 . 示例:12345Resume_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. 上面的代码有效,但它只保存并重命名文件的第一页,这意味着当前文件有5页。 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". 假设你有一个数组“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. 更新了答案,现在它将重命名所有页面“NewName”+索引号。

So it would be like: NewName0, NewName1, NewName2... all the way to the end of the array. 所以它就像:NewName0,NewName1,NewName2 ......一直到数组的末尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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