If you change:

    s/\.TMB$/T\.JPG/;

...to:

    s/\.TMB/T.JPG/i;

...you'll catch all cases of all cases. ;]

Meanwhile, here's a total treatment with a bit of commentary; it uses some neat grep tricks a friend taught me a while back to narrow the list of files before you start processing. I've only tested it a little but it should be correct.

Cheers!

--j

#!/usr/bin/env perl
#
# mvThumbs:
#   A quick script to move thumbnails
#

use strict;
use Cwd;

if (! @ARGV) {
  # We need arguments, durnit!
  warn "${0}: Insufficient arguments\n";
  warn "Syntax: $0 <dirName> ...\n";
  exit(1);
}

# They may give us directory paths which are relative to where we are,
# so let's be sure of where we are, eh?
my $origCWD = cwd();

foreach my $dirName (@ARGV) {
  unless (-d $dirName) {
    warn ">>> $dirName is not a directory ... skipping.\n";
  } else {
    # Can we write here? If not, we may as well skip it
    unless (-w $dirName) {
      warn ">>>> No write permissions in $dirName ... skipping\n";
    } else {
      # Get the list of thumbnails in this directory
      opendir(thumbDir, $dirName);
      my @thumbList = grep /\.TMB$/i, readdir(thumbDir);
      closedir(thumbDir);

      # To be lazy about having to construct pathnames, we'll just
      # move to the directory we're working with.
      chdir($dirName);
      print "\nIn directory: $dirName\n";

      # Run through the list and rename 'em
      foreach my $thumbFile (@thumbList) {
        my $newFile = $thumbFile;
        $newFile =~ s/\.TMB$/T.JPG/i;
        # You could force the filename into lower or upper case here
        # $newFile = lc($newFile);
        # $newFile = uc($newFile);
        unless (-e $newFile) {
          printf("%-30s => %s\n",$thumbFile, $newFile);
          rename($thumbFile, $newFile);
        } else {
          warn ">>> Can't move $thumbFile => $newFile in $dirName;\n";
          warn ">>>   $newFile already exists. Skipping.\n";
        }
      }
			
      # Back to home base for the next one
      chdir($origCWD);
    }
  }
}

print "\nAll done!\n";

In reply to Re: Only Works in UPPER CASE by purp
in thread renaming files by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.