Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- xx 1 abc.txt
- xx 2 def.txt
- xx 3 ghi.txt
- xx 3.5 jkl.txt
- xx 4a mno.txt
- xx 4b pqr.txt
- ...
- xx 100 end.txt
- xx 001 abc.txt
- xx 002 def.txt
- xx 003 ghi.txt
- xx 003.5 jkl.txt
- xx 004a mno.txt
- xx 004b pqr.txt
- ...
- xx 100 end.txt
- #!/usr/bin/perl
- opendir(DIR, ".");
- @files = sort(grep(/txt$/i, readdir(DIR)));
- closedir(DIR);
- $len=0;
- foreach $file (@files) {
- print $file."n";
- if ($file=~/xx (d+)(.*.txt)$/i) {
- $len=(length($1)>$len)?length($1):$len;
- }
- }
- foreach $file (@files) {
- if ($file=~/xx (d+)(.*.txt)$/i) {
- $newfile=sprintf("%0${len}d%s", $1, $2);
- rename("$file", "$newfile");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement