如何移动文件夹中的每四个项目?
我正在尝试制作一个脚本,将文件夹中的每四个项目移动到目标文件夹。到目前为止,我已经:
tell application "Finder"
set originFolder to folder choose folder
set dest1Folder to folder choose folder
set dest2Folder to folder choose folder
set quarter to 1
repeat with i from 1 to count of items in originFolder
if quarter is 1 then
move item i of originFolder to dest1Folder
else
move item i of originFolder to dest2Folder
end if
if quarter is 4 then
set quarter to 0
end if
set quarter to quarter + 1
end repeat
end tell
但这给了我
error "Finder got an error: Expected a reference." number -1727
为什么这不起作用以及什么会起作用?
I'm trying to make a script that will move every fourth item in a folder to a destination folder. So far I have:
tell application "Finder"
set originFolder to folder choose folder
set dest1Folder to folder choose folder
set dest2Folder to folder choose folder
set quarter to 1
repeat with i from 1 to count of items in originFolder
if quarter is 1 then
move item i of originFolder to dest1Folder
else
move item i of originFolder to dest2Folder
end if
if quarter is 4 then
set quarter to 0
end if
set quarter to quarter + 1
end repeat
end tell
but this gives me
error "Finder got an error: Expected a reference." number -1727
Why isn't this this working and what will work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的脚本中存在一些问题:
在设置
choosefolder
变量时,您必须在choosefolder
两边加上括号,以强制 Finder 将 别名由选择文件夹
返回到对象说明符:移动项目的循环将终止并出现索引越界错误,因为随着项目的移动,
originFolder
中的项目在循环的每次迭代中都会发生变化。更好的解决方案是首先计算应移动的文件的索引,然后让 Finder 一步执行移动操作:
There are a couple of problems in you script:
Upon setting up the
choose folder
variables you have to put parentheses aroundchoose folder
in order to force the Finder to convert the alias returned bychoose folder
to an object specifier:The loop that moves the items will terminate with an index out of bounds error because the number of items in the
originFolder
changes upon each iteration through the loop, as items are being moved.A better solution is to first compute the indexes of the files that should be moved and then have the Finder perform the move operation in one step: