我需要根据特定键自动重命名链接。一切正常,直到文件名包含“...%ef...”
Mac/Indesign 将“%ef”替换为冒号 -(来自 api:filePath - 文件路径(在 Mac OS 上以冒号分隔))
doc = app.activeDocument
links_list = doc.links
for(i=0;i<links_list.count();i++){
//[...some code...]
newKeyName[i] = links_list[i].name.replace(partOfOldName, newKey);
//[...some code...]
myFile = new File(links_list[k].filePath)
$.writeln(myFile.exists)//Console say - true. If name contains "...%ef..." - false
$.writeln(myFile.rename(newKeyName[i]))//...
}
我正在尝试使用替换
if(myFile.name.indexOf(":")>0){
$.writeln(myFile.name)//Console say - example: aaa%efbbb.png > aaa:bbb.png
myFolder = myFile.path
myName = myFile.name
myName = myName.replace(":","%ef")
myFile = new File(myFolder+"/"+myName);
$.writeln(myFile.exists)//Console say - false.
$.writeln(myFile.name)//Console say - cut file name after "%ef" example: aaa%efbbb.png > bbb.png
}
我正在尝试 linkResourceURI - 效果相同或最差。
我想在每个系统(mac/win)上重命名包含任何字符的链接文件...。我可以吗?
尝试根据现有文件路径创建一个 File 对象,并用新密钥替换旧名称。 通过这种方式,您可以重命名包含特殊字符的文件,并且与 Mac 和 Windows 系统兼容。
试试这个:
let doc = app.activeDocument;
let linksList = doc.links;
for (let i = 0; i < linksList.length; i++) {
let oldFile = new File(linksList[i].filePath);
if (oldFile.exists) {
let newFileName = oldFile.name.replace(partOfOldName, newKey);
let newFilePath = oldFile.parent + "/" + newFileName;
if (oldFile.rename(newFilePath)) {
// Update the link's file path in InDesign
linksList[i].relink(File(newFilePath));
} else {
// Handle the case where renaming failed
alert("Failed to rename the file: " + oldFile.name);
}
} else {
alert("File does not exist: " + linksList[i].filePath);
}
}