comparison bin/lren @ 4:94ee419ad047

Added bin-ec - a collection of scripts.
author Edho Prima Arief <me@myconan.net>
date Sat, 10 Jul 2010 12:38:52 +0000
parents
children
comparison
equal deleted inserted replaced
3:39ef7f7236fc 4:94ee419ad047
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 my $newname = $_;
11 print(qq(Could not find file "$_", skipping\n)) and next() unless -e $_;
12 $newname =~ s/_/ /g;
13 $newname =~ s/.* Ep([[:digit:]]+) .*/[Anime-Takeover] You're Under Arrest! - $1 [v2].mkv/;
14 $newname =~ s/ +/ /g;
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);