【发布时间】:2010-10-09 15:31:12
【问题描述】:
我有一个根文件夹,里面有子文件夹。它通常只有一个层次,但它可以更深。这些文件夹将包含不同的文件,包括一些 .rar 文件。我想创建一个遍历文件夹的递归函数,检查文件是否为 rar 文件并打开/提取它。该代码正在运行到第一级,没有任何问题。但是递归调用不起作用,而且苹果脚本的错误处理很糟糕。这是我到目前为止所做的代码。
set folderName to "Macintosh HD:Users:Teja:Desktop:Madhu Babu:"
process_folder("", folderName)
on process_folder(root, folderNameToProcess)
set fileExt to {".rar"}
tell application "Finder"
set theItems to every file of folder (root & folderNameToProcess)
repeat with theFile in theItems
copy name of theFile as string to FileName
repeat with ext in fileExt
if FileName ends with ext then
open theFile
delete theFile
end if
end repeat
end repeat
set theFolders to name of folders of folder (root & folderNameToProcess)
repeat with theFolder in theFolders
copy theFolder as string to TheFolderName
display dialog (folderNameToProcess & TheFolderName & ":")
try
process_folder(folderNameToProcess, TheFolderName & ":")
on error errStr number errorNumber
display dialog errStr
end try
end repeat
end tell
end process_folder
【问题讨论】:
标签: macos recursion applescript