#!/usr/bin/perl -w use strict; use Getopt::Long; my $i; my $j; my $dir; my $file; my $nodots=0; my $norename=0; sub usage { die "$0 [--norename] [--nodots]\n"; } GetOptions("norename" => \$norename, "nodots" => \$nodots, ) or usage; open (INVERT, ">/tmp/.revertrename") or die "Can't open /tmp/.revertrename: $!"; while ($i = shift @ARGV) { $i =~ s/"/\\"/g; $i =~ m#^(.*?)/?([^/]+)$#; ($dir,$file) = ($1, $2); $dir.="/" if $dir; $file =~ s/\./ /g if $nodots; # Fix broken windows characters $file =~ s/‚/é/g; $file =~ s/Š/é/g; $file =~ s/…/à/g; $file =~ s/ˆ/ê/g; $file =~ s/—/ù/g; $file =~ s/ ([a-z])/ \u$1/g; $file =~ s/^([a-z])/\u$1/g; $file =~ s/\s+$//; $j="$dir$file"; if ($i ne $j) { print "Going from $i \n"; print "to $j\n"; rename($i,$j) unless $norename; print INVERT "/bin/mv \"$j\" \"$i\"\n"; } else { print "$i will be left unchanged\n"; } }