#!/usr/bin/perl use Getopt::Std; if (($#ARGV < 0) || (getopts("f") == 0)) { print "usage: smash-case.pl [-f] \\n\n"; print "\tSmashes the case of filenames passed on the command line\n"; print "\tto all-lowercase if they don't contain any lowercase\n"; print "\tletters. If -f is given, smashes all filenames,\n"; print "\tregardless of their current case.\n\n"; print "\tExamples:\n"; print "\t\t\$ smash-case.pl FOO Bar qux\n"; print "\t\tFOO -> foo\n\n"; print "\t\t\$ smash-case.pl -f FOO Bar qux\n"; print "\t\tFOO -> foo\n"; print "\t\tBar -> bar\n"; print "\t\tqux -> qux\n"; exit 1; } do { # Find basename of file $basename = $filename = $ARGV[0]; $i = length($filename) - 1; while ($i >= 0) { $ch = substr($filename, $i, 1); if ($ch eq '/' or $ch eq '\\') { last; } --$i; } if ($i > 0) { $basename = substr($filename, $i + 1); } if (($opt_f) || (!($basename =~ /[a-z]/))) { # Filename has no lowercase letters in it, so smash it print "$filename -> \L$basename"; rename($filename, "\L$filename") || print " -- failed: $!"; print "\n"; } shift; } while ($#ARGV >= 0);