comparison bin/putend @ 88:917b525eaee0

Put [End] to files. Still in perl D:
author Edho Prima Arief <me@myconan.net>
date Wed, 19 Oct 2011 06:50:41 +0000
parents
children
comparison
equal deleted inserted replaced
87:c884853b25d1 88:917b525eaee0
1 #!/usr/bin/env perl
2
3 use warnings;
4 use strict;
5 use File::Basename;
6
7 my @files = @ARGV or print("Usage: ",basename($0)," file1 ... fileN\n") && exit(1);
8 my $skip=0;
9 foreach (@files) {
10 print(qq(Could not find file "$_", skipping\n)) and next() unless -e $_;
11 my $newname = $_;
12 $newname =~ s/(\.[^.]+$)/[End]$1/;
13 $newname =~ s/ (\[.*\])(\[End\])\./ $2$1./;
14 $newname =~ s/([^ ])(\[End\]\.)/$1 $2/;
15 print(qq($_: $newname already exists, skipping\n)) and next() if -e $newname and $_ ne $newname;
16 if ($_ eq $newname) {
17 print("$_: no need to rename, skipping\n");
18 } else {
19 if($skip==1) { print("Result: $_ --> $newname\n"); }
20 else {
21 if(rename($_, $newname)) { print("$_ -> $newname\n"); }
22 else { print("$_: rename failed\n"); }
23 }
24 }
25 next();
26 }
27
28 exit(0);