#!/usr/bin/perl
#
# Prabu 8/28/04
#
# This script file has been customized for Windows 32
#
# This perl script rename prefix of all files present in the given directory
#

use strict;

if ($#ARGV != 2) { # in Perl, argcnt is zero for one argument
    die "Usage: perl $0 srcImageDir originalPrefix newPrefix \n";
}


my $dirName = $ARGV[0];
my $oldPrefix = $ARGV[1];
my $newPrefix = $ARGV[2];

#print " Directory name: $dirName\n";
#print " Old Prefix: $oldPrefix\n";
#print " New Prefix: $newPrefix\n";
#exit(0);

#$f =~ s#'#\\'#g; # prefix meta char for any apostraphies
my @files = `dir/b $dirName`; # DIR/B lists files as well as folders one per line without summary

my $filecount = 0;
chdir($dirName) or die "Unable to enter dir $dirName:$!\n";
# foreach works in DOS
foreach my $file (@files) {
  $file =~ s/\s*$//;
  if ($file =~ /jpg$/oi) {
    my $newfile = $file;
    $newfile =~ s/$oldPrefix/$newPrefix/;
    system("rename $file $newfile ");
    $filecount++;
  }
}
chdir("..");
print "\n In directory $dirName, $filecount files have been renamed \n\n";

exit(0);
