comparison bin/rmcrc @ 115:7c3cdb235bbb

The reverse of putcrc: rmcrc.
author Edho Prima Arief <edho@myconan.net>
date Fri, 21 Oct 2011 13:38:18 +0700
parents bin/putend@917b525eaee0
children 66c32422a3d4
comparison
equal deleted inserted replaced
114:eb4dddd48f29 115:7c3cdb235bbb
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=1;
9 foreach (@files) {
10 print(qq(Could not find file "$_", skipping\n)) and next() unless -e $_;
11 my $newname = $_;
12 $newname =~ s/\[[[:xdigit:]]{8}\]//i;
13 $newname =~ s/ *(\.\w+)$/$1/;
14 print(qq($_: $newname already exists, skipping\n)) and next() if -e $newname and $_ ne $newname;
15 if ($_ eq $newname) {
16 print("$_: no need to rename, skipping\n");
17 } else {
18 if($skip==1) { print("Result: $_ --> $newname\n"); }
19 else {
20 if(rename($_, $newname)) { print("$_ -> $newname\n"); }
21 else { print("$_: rename failed\n"); }
22 }
23 }
24 next();
25 }
26
27 exit(0);