删除文件时循环停止

时间:2015-02-10 16:01:56

标签: applescript

下面的脚本应该删除所有以.aux等结尾的文件。 在当前目录中(即在取景器窗口中显示的目录) 该脚本似乎停止删除.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

1 个答案:

答案 0 :(得分:0)

这是使用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时,请非常小心。错误位置的一个空格字符可以删除所有内容。