#!perl # replace the string in all file at this directory. print "example:3.1.1SC\n"; $top = <>; chop $top; $head1 = "詳細仕様書<"; $end1 = ">.doc"; $head2 = "概要フロー<"; $end2 = ">.xls"; opendir THISDIR, "." or die "serious dainbramage: $!"; @allfiles = grep !/^\.\.?$/, readdir THISDIR; closedir THISDIR; foreach $file (@allfiles){ if (-d $file){ print "$file ----> Directory.\n"; } elsif ($file eq "myrename.pl" | $file eq "myrename.BAK"){ print "$file ----> This file.\n"; } elsif ($file =~ /\.doc$/) { $from = $file; $file =~ /(........-..)(.*)\)\.doc/; $to = $top . $head1 . $1 . "(" . $2 . ")$end1"; rename($from, $to); print $from . "->" . $to . "\n"; } elsif ($file =~ /\.xls$/) { $from = $file; $file =~ /(........)(.*)\.xls/; $to = $top . $head2 . $1 . "(" . $2 . ")$end2"; rename($from, $to); print $from . "->" . $to . "\n"; } } exit(0);