-
sub lc_filenames{ my($dir)=@_; $dir||="./"; #sets to current directory if it wasn't passed a param +eter opendir DIR, $dir; while(defined($file=readdir DIR)){ if(-f ($dir.$file)){ if($file=~/[A-Z]/){ $newname=lc($file); if(-e ($dir.$filename)){ print "File exists. Replace it? Y/N\n"; if(<> and /^y/i){ rename($dir.$file,$dir.$newname); } } else{ rename($dir.$file,$dir.$newname); } } } } }

Replies are listed 'Best First'.
RE: Lowercases all filenames within a directory
by Anonymous Monk on Feb 25, 2000 at 18:49 UTC
    found a bug in this version that is posted.. Search pattern not terminated at line blah. problem is there is a missing / to end the search pattern the if statement if($file=~/A-Z){ should read: if ($file=~/A-Z/){
      fixed now, thanks
RE: Lowercases all filenames within a directory
by Anonymous Monk on Mar 03, 2000 at 10:04 UTC
    This could cause problems if you already have a file with the lower case name. Maybe a quick if ( -e $newname )... would be good.
      good thinking... I added a prompt for the user to choose whether or not to replace the file.