#!/usr/bin/perl
# ----------------------------------------------------------------------
# Copyright (C) 2001 Bodo Bauer <bb@bb-zone.com>
#
# This program is free software; you can redistribute it and/or 
# modify it under the terms of the GNU General Public License as 
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version. 
#
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
# General Public License for more details. 
#
# You should have received a copy of the GNU General Public License 
# along with this program; if not, write to the Free Software 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, 
# MA 02111-1307, USA. 
# ----------------------------------------------------------------------
# Little script to move all *.JPG files to *.jpg in given directory
# ----------------------------------------------------------------------
# Changelog
#
# 2001-06-06   BB   Initial release
# 2002-04-06   BB   Allow spaces in file names
# ----------------------------------------------------------------------
use strict;

if ( $#ARGV  != 0 ) {
    print STDERR<<END;
$0 <directory>

Rename *.JPG to *.jpg
END
    exit ( 1 );
}

if ( opendir ( DIR, $ARGV[0] ) ) {
    my @files = readdir ( DIR );
    close ( DIR );

    for ( my $i=0; $i<=$#files; $i++ ) {
	if ( $files[$i] =~ /(.*)\.JPG$/ ) {
	    system ( 'mv', '-v', "$ARGV[0]/$files[$i]",  "$ARGV[0]/$1.jpg" );
	}
    }
    exit ( 0 );
}
print "Can not read $ARGV[0]\n";
exit ( 1 );

