#!/usr/bin/env perl
# @(#) convert all filenames recursively to lower case.
# (c) 2006 by Dirk Jagdmann <doj@cubic.org>

foreach(@ARGV)
  {
    lower($_, ".");
  }

sub lower
  {
    my ($file, $dir) = @_;
    
    return if $file eq '.';
    return if $file eq '..';

    $dir.="/" unless $dir =~ /\/$/;

    my $df="$dir$file";

    if(-d $df)
      {
	local *DIR;
	opendir(DIR, $df) or die "could not open $df";
	while(my $ff=readdir(DIR))
	  {
	    lower($ff, $df);
	  }
	closedir(DIR);
      }

    my $l=lc($file);
    if($l ne $file)
      {
	rename "$dir$file", "$dir$l" or die "could not rename $dir$file -> $dir$l";
      }

    return 1;
  }
