我正在尝试编写一个脚本来删除所选文件夹及其所有子文件夹中的所有.tmp文件。
我目前已将其设置为:
set sequenceFolder to choose folder with prompt "Please select a sequence:"
try
tell application "Finder"
set SubFolders to every folder of entire contents of sequenceFolder
repeat with aFolder in SubFolders
delete (every item of folder (sequenceFolder) whose name ends with ".tmp")
delete (every item of folder (SubFolders) whose name ends with ".tmp")
delete (every item of folder (aFolder) whose name ends with ".tmp")
display dialog ("Files Deleted!") buttons {"OK"}
end repeat
end tell
on error
display dialog ("Error. Couldn't Delete Files") buttons {"OK"}
end try
它目前可以删除sequenceFolder中的文件,但不能删除任何子文件夹。我也喜欢它以递归方式查找子文件夹,但我不知道如何。请帮忙!
答案 0 :(得分:0)
我建议使用shell命令find
和rm
,因为它们可以考虑给定文件夹及其子文件夹中的所有文件,并且它比Finder快得多。
以下代码会立即删除所选文件夹的所有文件夹和子文件夹中具有指定文件扩展名的所有文件,而不会将它们放入废纸篓文件夹
set theFolder to POSIX path of (choose folder with prompt "Please select a sequence:")
do shell script " /usr/bin/find " & quoted form of theFolder & " -name '*.tmp' -exec rm {} \\;"
display dialog ("Files Deleted!") buttons {"OK"}