我有一個根文件夾,其中有子文件夾。它通常只有一個層次,但可以更深一層。這些文件夾將有不同的文件,包括一些.rar
文件。我想創建一個遍歷文件夾的遞歸函數,檢查文件是否是rar文件並打開/解壓縮它。代碼正在努力解決任何問題。但遞歸調用不起作用,蘋果腳本的錯誤處理非常糟糕。這是我迄今爲止所做的代碼。AppleScript遞歸處理文件夾中的文件
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