Mercurial > ec-dotfiles
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/putcrc.pl Wed Oct 26 15:22:00 2011 +0700 @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use String::CRC32; + +my @files = @ARGV or print("Usage: ren file1 ... fileN\n") && exit(1); +my $skip=0; +foreach (@files) { + my $newname = $_; + open(FILE,$_); + my $crc=sprintf("%08X",crc32(*FILE)); + close(FILE); + $newname =~ s/(.*)\.([^.]*)/$1 [$crc].$2/; + $newname =~ s/\] (\[$crc)/]$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("$_ --> $newname\n"); } + else { + if(rename($_, $newname)) { print("$_ -> $newname\n"); } + else { print("$_: rename failed"); } + } + } + next(); +} + +exit(0);