Mercurial > ec-dotfiles
comparison bin/putcrc.pl @ 124:5bafb912837e
Massive addition of old scripts collection.
| author | Edho Prima Arief <edho@myconan.net> |
|---|---|
| date | Wed, 26 Oct 2011 15:22:00 +0700 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 123:173833e4ba35 | 124:5bafb912837e |
|---|---|
| 1 #!/usr/bin/perl | |
| 2 | |
| 3 use warnings; | |
| 4 use strict; | |
| 5 use String::CRC32; | |
| 6 | |
| 7 my @files = @ARGV or print("Usage: ren file1 ... fileN\n") && exit(1); | |
| 8 my $skip=0; | |
| 9 foreach (@files) { | |
| 10 my $newname = $_; | |
| 11 open(FILE,$_); | |
| 12 my $crc=sprintf("%08X",crc32(*FILE)); | |
| 13 close(FILE); | |
| 14 $newname =~ s/(.*)\.([^.]*)/$1 [$crc].$2/; | |
| 15 $newname =~ s/\] (\[$crc)/]$1/; | |
| 16 print(qq($_: $newname already exists, skipping\n)) and next() if -e $newname and $_ ne $newname; | |
| 17 if ($_ eq $newname) { | |
| 18 print("$_: no need to rename, skipping\n"); | |
| 19 } else { | |
| 20 if($skip==1) { print("$_ --> $newname\n"); } | |
| 21 else { | |
| 22 if(rename($_, $newname)) { print("$_ -> $newname\n"); } | |
| 23 else { print("$_: rename failed"); } | |
| 24 } | |
| 25 } | |
| 26 next(); | |
| 27 } | |
| 28 | |
| 29 exit(0); |
