我想查看一个文件夹,以选择其名称包含"abc“的每个文件。
以下是我的AppleScript代码:
set myFolder to (((path to library folder from user domain) as string) & "FOLDER") as alias
tell application "Finder"
    set deleted123 to every file of folder myFolder whose name contains "abc"
        repeat with oneFile in deleted123
        if exists (deleted123) then set end of deleted123 to oneFile & return
        --Do something
        end repeat
    
    if deleted123 ≠ {} then
        --Do something else with the selected.
    end if
end tell代码完美无缺的工作在高塞拉,也就是说,它发现所有的文件,其名称包含"abc",但它没有在蒙特利。
有什么问题吗?如何改进这段代码?
非常感谢的帮助。
发布于 2022-06-27 04:57:14
有两大错误:
myFolder是别名说明符。您添加了folder关键字,这是一个双重引用,删除第一个as alias中的as alias是一个查找文件说明符,您不能追加字符串return。也许文件说明符被静默地强制在Sierra中字符串。如果您想使用文件引用,那么无论如何return语句都没有意义。另一个错误做法是在枚举时修改数组deleted123。创建一个额外的变量。
重复循环也没有任何意义,因为exists (deleted123)总是true,即使您检查循环oneFile中的当前项,它也始终是true。
https://stackoverflow.com/questions/72766854
复制相似问题