diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/lren	Sat Jul 10 12:38:52 2010 +0000
@@ -0,0 +1,28 @@
+#!/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=0;
+foreach (@files) {
+	my $newname = $_;
+	print(qq(Could not find file "$_", skipping\n)) and next() unless -e $_;
+  $newname =~ s/_/ /g;
+  $newname =~ s/.* Ep([[:digit:]]+) .*/[Anime-Takeover] You're Under Arrest! - $1 [v2].mkv/;
+	$newname =~ s/ +/ /g;
+	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);