在我看来,您正在处理文件夹的名称,以及文件夹的字符(文件夹的项目)
请与此进行比较,结果应该正确:
tell application "Finder"
set theFolder to ((path to desktop folder as text) & "Images")
set myImages to the name of every file of folder theFolder
set indexOfFolder to (count myImages)
set newname to "Z picture " as string
repeat with x from 1 to indexOfFolder
set name of item x of folder theFolder to newname & x & ".JPG"
end repeat
end tell
它仍然不是无bug的,下一个差异是当您将内容收集到
myImages
变量,但您寻址文件夹的项,这是两个不同的对象类。为了避免冗余,我也在最后一个实现中将文件夹设置为。也请注意我把胁迫放在什么地方,我把胁迫去掉了,因为它们是多余的。
tell application "Finder"
set theFolder to folder ((path to desktop folder as text) & "Images")
set myImages to the name of every file of theFolder
set indexOfFolder to (count myImages)
set newname to "Z picture " as string
repeat with x from 1 to indexOfFolder
set name of file x of theFolder to newname & x & ".JPG"
end repeat
end tell
即使当文件更改名称时,此版本仍应有效,因为文件列表是预先获得的。
tell application "Finder"
set theFolder to folder ((path to desktop folder as text) & "Images")
set myImages to every file of theFolder
set indexOfFolder to (count myImages)
set newname to "Z picture " as string
repeat with x from 1 to indexOfFolder
set name of item x of myImages to newname & x & ".JPG"
end repeat
end tell