Lowercase.pl

Renames any mixed-case filenames so that only all-lowercase filenames remain.

Requirements

Perl 5 or later. Knowledge of the location of your perl executable. (generally can be determined with "which perl" on a Unix machine)

Installation

1. Save the code below as lowercase or lowercase.pl, changing the first line if necessary (the #! line) to point to your Perl executable.
2. Change the permissions on lowercase/lowercase.pl to make it executable (e.g., "chmod a+x lowercase.pl").
3. Move lowercase/lowercase.pl to some directory on your path (e.g., "mv lowercase.pl ~/bin").

Usage

lowercase filespec
where filespec is a wildcarded filename specification.

If two or more filenames are differentiated only by case then one or more of the files will be left unrenamed.

Source Code

#!/usr/bin/perl

if (length($ARGV[0]) == 0)
  {
  print "Renames files (if necessary) to give them lowercase names.\n";
  print "\nsyntax:  lowercase <filespec> [<filespec> ...]\n";
  }


my $seen = 0;
my $changed = 0;

while (@ARGV)
  {
  my $filespec = pop(@ARGV);
  my $original_filename;

  while ($original_filename = <${filespec}>)
    {
    my $lowercase_filename = "\L$original_filename\E";
    if ($lowercase_filename ne $original_filename)
      {
      if (-e $lowercase_filename)
        {
        print "$original_filename -> $lowercase_filename",
              " (not renamed due to imminent name collision)\n";
        }
      else
        {
        print "$original_filename -> $lowercase_filename\n";
        rename( $original_filename, $lowercase_filename );
        $changed++;
        }
      }
    $seen++;
    }
  }

print "\n$seen filenames examined, $changed files renamed.\n\n";

jasonc.com

Please note that most of this site was last updated in 2003.

 - Home page
Work
 - Overview
 - Consulting
 - Zack Systems
Art
 - Photography
 - Mobiles
Code / Docs
 - Palm Bus Schedule
 - Small perl scripts
 - Old stuff
About Jason
 - Contact Info
 - Tools
 - Drop Box
 - Weblog
  copyright © 2003 Jason D. Campbell, All Rights Reserved.
  File /docs/perl/lowercase.mason, updated 12 May 2003