【发布时间】:2015-05-30 23:11:10
【问题描述】:
我编写了这个简单的脚本来更改我桌面上图像文件夹的文件名。该脚本在第一次运行时有效,但是当我使用变量 newName 的不同字符串重新运行它时(相同的字符串会引发错误:文件名已存在)。它只会更改“文件夹的第 x 项”的偶数个名称。 有人可以告诉我这是如何发生的以及如何避免这种特殊行为。我很难弄清楚这一点。 非常感谢您。
tell application "Finder"
set theFolder to ((path to desktop folder) & "Images") as string as alias
set myImages to the name of every file of theFolder
set indexOfFolder to (count items in myImages) as number
set newName to "whateverName" as string
repeat with x from 1 to indexOfFolder
set name of item x of theFolder to newName & x & ".JPG"
end repeat
end tell
编辑:经过更多测试,问题似乎不会完全指向不变的奇数。有超过 20 个文件,它似乎从 20 切换到不会重命名的偶数。
【问题讨论】:
-
你能用英语解释一下脚本实际上应该做什么吗?目前,我只能看到它不起作用,但我不知道它需要做什么才能正常工作。
标签: image applescript filenames rename