ネットで拾った画像を整理するため、一旦ファイル名を作成日でリネームしてから整理することにした。
以下、リネーム処理で使ったスクリプトです。
1.リネームするファイルが入ったフォルダを指定する。
2.フォルダにある全ファイル名を取得する。
3.ファイルの作成日を取得し、年月日時分秒を数値に変換する(先頭ゼロ埋め)。
4.既に同じファイル名が存在しないか確認し、同じ名前のファイルがある場合は末尾に任意の番号をつける。
5.ファイルをリネームする。
以下、リネーム処理で使ったスクリプトです。
1.リネームするファイルが入ったフォルダを指定する。
2.フォルダにある全ファイル名を取得する。
3.ファイルの作成日を取得し、年月日時分秒を数値に変換する(先頭ゼロ埋め)。
4.既に同じファイル名が存在しないか確認し、同じ名前のファイルがある場合は末尾に任意の番号をつける。
5.ファイルをリネームする。
(* 選択したフォルダ内のファイル名を 作成日付でリネームする *) on run tell choose folder -- キャンセルを選んだ場合は終了 on error errText number errNum if errNum is not -128 then -- キャンセル以外のエラーが発生した場合は内容を表示 display dialog (errText) & "\nerror number:" & (errNum) buttons {"OK"} default button "OK" with icon 2 end if return end try -- 選択したフォルダの全ファイル名取得 set theFiles to every file of aFol set newFiles to {} -- ファイルの数だけ以下を実行 repeat with aFile in theFiles -- 作成日取得 set cDate to creation date of aFile set fy to year of cDate set fmo to month of cDate as number set fd to day of cDate set fH to hours of cDate set fmi to minutes of cDate set fs to seconds of cDate -- 先頭ゼロ埋め set fmo to my fillzero(fmo) set fd to my fillzero(fd) set fH to my fillzero(fH) set fmi to my fillzero(fmi) set fs to my fillzero(fs) -- 拡張子の取得 set ext to name extension of aFile -- 新ファイル名(拡張子なし) set newNameNoExt to fy & fmo & fd & "_" & fH & fmi & fs as Unicode text -- 新ファイル名(拡張子あり) set newName to newNameNoExt & "." & ext as Unicode text set cnt to 1 -- リネームしたファイルの中から同じものがないか検索する repeat with tmpFile in newFiles -- リネーム後のファイル名が存在した場合 if newName = (tmpFile as Unicode text) then -- 一意番号付与 set newName to newNameNoExt & " (" & cnt & ")." & ext as Unicode text set cnt to cnt + 1 end if end repeat -- ファイル名変更 set name of aFile to newName -- リネームリストへ追加 set the end of newFiles to newName end repeat end tell display dialog "リネーム処理が完了しました" end run (* ゼロ埋め *) on fillzero(srcNo) set dstNo to "0" & srcNo if (length of dstNo) > 2 then set dstNo to characters ((length of dstNo) - 1) thru (length of dstNo) of dstNo as text end if return dstNo end fillzero