删除文件时循环停止

Loop stalling when deleting files

下面的脚本应该删除所有以 .aux 等结尾的文件。 在当前目录中(即在查找器中显示的目录 window) 该脚本似乎在删除 .aux 文件时停滞不前。 欢迎任何提示。


try

    tell application "Finder"

        set lieu to target of window 1

        set finale to {".aux", ".log", ".bak", ".out", ".synctex.gz"} as list

        repeat with x in finale

            try

                delete (every item of lieu whose name ends with x)

            end try

        end repeat

    end tell

    say "Mess cleaned up"

on error

    display dialog ("Error. Couldn't Delete the File") buttons {"OK"}

end try

这里是一个使用rm的版本:

tell application "Finder"
    set lieu to target of window 1 as text
    set posixPathOfLieu to POSIX path of lieu
    set shellScript to "cd" & space & quoted form of posixPathOfLieu & ";rm *.aux *.log *.bak *.out *.synctex.gz"
    try
        do shell script shellScript
    end try
end tell

使用rm时请格外小心。一个 space 字符在错误的地方可以删除所有内容。