DTP駆け込み寺

No.20632へ返信

記事投稿フォーム
補助
送信

[ 返信 ]

Re: ファイル名の変更について

添付画像がmacの様なのでアップルスクリプトで作りました。
数字+拡張子のファイルを2階層分のフォルダ名+アンダーバーを付加します。

on open _List
set n_list to number of (_List)
repeat with i from 1 to n_list
set i_List to item i of _List as Unicode text
set i_path to POSIX path of i_List

if i_path ends with "/" then --フォルダ
--数字+拡張子のファイルのファイルを検索
set findOpt to " -regex '.*/([0-9]*\\..*)$' -type f"
set cmd to "find -E " & quoted form of i_path & findOpt
set FileList to do shell script cmd

set n_FileList to number of (every paragraph of FileList)
repeat with j from 1 to n_FileList
set j_filePath to paragraph j of FileList
--スラッシュが重複するので整形
set cmd_Perl to "echo " & quoted form of j_filePath & " | perl -pe 's:/+:/:g;'"
set j_filePath to do shell script cmd_Perl
--リネームルール:フォルダ2階層分をファイル名に付加する
set cmd_Perl to "echo " & quoted form of j_filePath & " | perl -pe 's:^(.*)/(.*)/(.*)/(.*)$:$1/$2/$3/$2_$3_$4:g;'"
set reName to do shell script cmd_Perl
--リネーム実行
do shell script "mv " & quoted form of j_filePath & space & quoted form of reName
end repeat
end if
end repeat
end open

[20632] エスパー魔美 (2021/10/13 Wed 13:16)