我想用applescript更改成千上万个文件名。
文件名都是以这种方式创建的:
第一部分-第二部分XX.xxx
其中XX为特定数字,.xxx为jpg或png扩展名。
我想简单地更改周围的部分,以使其变为:
secondPart-firstPart XX.xxx
我想出了这个办法,但是我的编码技能使我不满意。
tell application "Finder" to set aList to every file in folder "ImageRename"
set text item delimiters to {" - ", "."}
repeat with i from 1 to number of items in aList
set aFile to (item i of aList)
try
set fileName to name of aFile
set firstPart to text item 1 of fileName
set secondPart to text item 2 of fileName
set thirdPart to text item 3 of fileName
set newName to secondPart & " - " & firstPart & "." & thirdPart
set name of aFile to newName
end try
end repeat
这仅适用于数字坚持第二部分。这样就变成了:
SecondPart XX-firstPart.xxx
如何使两个整数成为文本项定界符?
请帮助我,并一路教我:-)
只需使用空格作为定界符并构建零件。编辑:在文本部分中留有空格。
tell application "Finder" to set aList to every file in folder "ImageRename"
set AppleScript's text item delimiters to " "
repeat with i from 1 to number of items in aList
set aFile to (item i of aList)
try
set fileName to name of aFile
set lastParts to text item -1 of fileName
set wordParts to (text items 1 thru -2 of fileName) as string
set AppleScript's text item delimiters to " - "
set newName to {text item 2 of wordParts, "-", text item 1 of wordParts, lastParts}
set AppleScript's text item delimiters to " "
set name of aFile to (newName as string)
end try
end repeat
set AppleScript's text item delimiters to ""
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句