ファイル名一括変更

perlネタ

仕事で、ファイル名を一括変更する必要があり、作ってみた。

use strict;
use warnings;
use File::Copy 'move';


my ($dir, $from, $to) = @ARGV;
chdir $dir
    or die "NG $dir:$!";

my @all_files = glob "*.pdf";
my $to_all_file;

foreach my $all_file (@all_files){
    $to_all_file = $all_file;
    $to_all_file =~ s/$from/$to/;
    move $all_file ,$to_all_file;
}

No.61というフォルダの中にある63という数字が含まれているファイルを一括して61に変更

perl no.pl No.61 63 61

余りperlは得意ではないですが、実用的なスクリプトが作れると嬉しいですね。