私は自分がやりたいことをする Applescript を書きました。あれは:
ファイル名に基づいて、移動元フォルダーから移動先フォルダー内のサブフォルダーのサブフォルダーにファイルを移動します。
ただし、私の問題は、スクリプトにエラー処理がないことです。
例: ファイル「130299_1833_9_Actierondje Cantomobili Figo 400mm_LR.jpg」は、保存先フォルダーのサブフォルダー「0001833」のサブフォルダー「00009」に配置されます
ただし、ファイル名の 2 番目と 3 番目の部分が実際に数値/整数であるかどうかをスクリプトで確認したいと思います。それらが数値/整数でない場合、ファイルはエラー フォルダーに移動され、スクリプトはソース フォルダーの次のファイルで続行されます。
例: ファイル「130299_9_Actierondje Cantomobili Figo 400mm_LR.jpg」と「130299_1833_Actierondje Cantomobili Figo 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