in reply to How to rename to lowercase every file in a directory and its subdirectories?

I'm no perl monk, but here's a tiny extension to Robin's answer, which also changes directory names to lowercase. A script which has just saved my skin.
#!/usr/bin/perl -w use strict; my $path_to_dir = shift; dir("$path_to_dir"); sub dir { rename "$_[0]","\L$_[0]"; $_[0]="\L$_[0]"; opendir(DIR,"$_[0]"); my @list_of_files = readdir(DIR); foreach(@list_of_files) { if($_ ne "." && $_ ne "..") { if(-d "$_[0]/$_") { dir("$_[0]/$_"); } else { rename "$_[0]/$_","$_[0]/"."\L$_"; } } } }
  • Comment on Re: How to rename to lowercase every file in a directory and its subdirectories?
  • Download Code

Replies are listed 'Best First'.
Re: Answer: How to rename to lowercase every file in a directory and its subdirectories?
by Happy-the-monk (Canon) on Sep 25, 2004 at 23:07 UTC

    rename "$_[0]","\L$_[0]";

    This fails if the lowercase version of the directory already exists and is not empty.
    Maybe worse is, it removes an existing but empty directory of the lowercase name.

    So best to think about a warning:

    unless ( -e "\L$_[0]" ) { rename "$_[0]","\L$_[0]"; } else { warn qq(been too afraid to move "$_[0]" to "\L$_[0]\E" - a file of + that name already exists.\n); }

    Edit:
    One further thought: the script might save some time skipping the renaming
    if the original file or directory already is all-lowercase.

    Cheers, Sören