changeset 88:917b525eaee0

Put [End] to files. Still in perl D:
author Edho Prima Arief <me@myconan.net>
date Wed, 19 Oct 2011 06:50:41 +0000
parents c884853b25d1
children 9b91e702c19c
files bin/putend
diffstat 1 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/putend	Wed Oct 19 06:50:41 2011 +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) {
+  print(qq(Could not find file "$_", skipping\n)) and next() unless -e $_;
+  my $newname = $_;
+  $newname =~ s/(\.[^.]+$)/[End]$1/;
+  $newname =~ s/ (\[.*\])(\[End\])\./ $2$1./;
+  $newname =~ s/([^ ])(\[End\]\.)/$1 $2/;
+  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);