Applescript 使用Apple脚本删除父文件夹中的文件

Applescript 使用Apple脚本删除父文件夹中的文件,applescript,Applescript,我想删除(移动到垃圾箱)父文件夹和当前文件夹中所有扩展名为“.acr”的文件。我这样试过: tell application "Finder" try delete (every file of folder of (file (path to me)) whose name ends with ".acr") delete (every file of container of (file (path to me)) whose name ends wi

我想删除(移动到垃圾箱)父文件夹和当前文件夹中所有扩展名为“.acr”的文件。我这样试过:

tell application "Finder"
    try
        delete (every file of folder of (file (path to me)) whose name ends with ".acr")
        delete (every file of container of (file (path to me)) whose name ends with ".acr")
    end try
end tell
仅删除当前文件夹中的文件。父文件夹中的文件不会被删除。

如果当前文件夹是指在Finder中打开的当前文件夹,则这将检索该文件夹及其父文件夹中的所有
.acr
文件,然后将其移动到垃圾箱:

如果你真的想像你在代码片段中所做的那样实现我的路径,那么问题在于…的
文件夹和…
容器本质上意味着相同的东西,因此两行代码都在同一个目录中查找文件:即,脚本所在的目录,如果您是从脚本编辑器内部运行它

以下是修复方法:

    tell application "Finder"
        set f to every file ¬
            of folder ¬
            of (path to me) ¬
            whose name extension is "acr"

        set g to every file ¬
            of container ¬
            of folder ¬
            of (path to me) ¬
            whose name extension is "acr"

        delete f & g
    end tell
    tell application "Finder"
        set f to every file ¬
            of folder ¬
            of (path to me) ¬
            whose name extension is "acr"

        set g to every file ¬
            of container ¬
            of folder ¬
            of (path to me) ¬
            whose name extension is "acr"

        delete f & g
    end tell