Mercurial > ec-dotfiles
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/rmcrc Fri Oct 21 13:38:18 2011 +0700 @@ -0,0 +1,27 @@ +#!/usr/bin/env perl + +use warnings; +use strict; +use File::Basename; + +my @files = @ARGV or print("Usage: ",basename($0)," file1 ... fileN\n") && exit(1); +my $skip=1; +foreach (@files) { + print(qq(Could not find file "$_", skipping\n)) and next() unless -e $_; + my $newname = $_; + $newname =~ s/\[[[:xdigit:]]{8}\]//i; + $newname =~ s/ *(\.\w+)$/$1/; + print(qq($_: $newname already exists, skipping\n)) and next() if -e $newname and $_ ne $newname; + if ($_ eq $newname) { + print("$_: no need to rename, skipping\n"); + } else { + if($skip==1) { print("Result: $_ --> $newname\n"); } + else { + if(rename($_, $newname)) { print("$_ -> $newname\n"); } + else { print("$_: rename failed\n"); } + } + } + next(); +} + +exit(0);