我已經寫了一個Applescript,做我想做的事情。即:錯誤處理在Applescript根據文件名將文件移動到目標文件夾
根據文件名將文件從源文件夾移動到目標文件夾中的子文件夾的子文件夾。
但我的問題是腳本中沒有錯誤處理。
舉例: 文件 「130299_1833_9_Actierondje Cantomobili菲戈400mm_LR.jpg」獲取目標文件夾放置在子文件夾「00009」的子目錄「0001833」
不過,我想腳本檢查文件名的第二和第三部分實際上是數字/整數。如果它們不是數字/整數,則文件將移至錯誤文件夾,並且腳本將繼續處理源文件夾的下一個文件。
舉例: 文件 「130299_9_Actierondje Cantomobili菲戈400mm_LR.jpg」 以及 「」 130299_1833_Actierondje Cantomobili菲戈400mm_LR.jpg」獲得放置在錯誤的文件夾
目前,我有以下的AppleScript:
set source_folder to alias "Macintosh HD:Users:Roy:Desktop:_LR JPG's" --as alias
set destination_folder to "Macintosh HD:Users:Roy:Desktop:Produktcommunicatie test" as alias
set org_delimit to text item delimiters of AppleScript
tell application "Finder"
set source_files to files of source_folder
--display a dialog if there are no files to move
if number of source_files is 0 then
display dialog "There are no files to move" buttons {"OK"} default button 1
end if
repeat with this_file in source_files
--set the leveranciersnummer en modelnummer
set text item delimiters of AppleScript to {"_"}
set mgDocname to name of this_file
set mgLeveranciersnummer to text -7 thru -1 of ("0000000" & text item 2 of mgDocname)
set mgModelnummer to text -5 thru -1 of ("00000" & text item 3 of mgDocname)
--check if the folders already exist in the destination, if not, create the folders
if (exists folder mgLeveranciersnummer of folder destination_folder) is false then
make new folder at destination_folder with properties {name:mgLeveranciersnummer}
end if
set text item delimiters of AppleScript to org_delimit
set model_folder to destination_folder & mgLeveranciersnummer as string
--set model_folder to alias model_folder
if (exists folder mgModelnummer of folder model_folder) is false then
make new folder at model_folder with properties {name:mgModelnummer}
end if
set final_path to model_folder & ":" & mgModelnummer as string
move this_file to final_path with replacing
end repeat
--display a dialog if the all the files are moved
display dialog "All the files are moved to " & destination_folder buttons {"Thanks!"} default button 1
end tell
所以基本上你只需要看看他們是數字或不...看看這個帖子http://stackoverflow.com/questions/918493/how-do-i-check-if-text -can-be-converted-to-a-number-in-applescript – mcgrailm
這確實是我想要做的,但是如果無法將變量設置爲數。 – sirbaxx
我在你的腳本中沒有看到你正在測試的數字 – mcgrailm