xuantl wrote:
Hi all,

Hello,

I wan't to change name of all the files in a directory(incluing sub
directorys) to lowercase.

the code:
-------------------------------------------
use File::Find;
$rootDir='.';
find (\&lowerCase, $rootDir);
find (sub{print "$File::Find::name\n"}, $rootDir);

sub lowerCase {
        $oldName = "$File::Find::name";
        $newName = "\L$File::Find::name";
        print (rename ($oldName, $newName));
        print " rename result: \"$oldName\" - \"$newName\"\n";
};
-------------------------------------------

But it only works for files in the top directory("."), and no effect to
all other files in sub directorys. Any help?
I'm a beginner. If it's a stupid question for you, please don't hit me!

I assume that you are not trying to do this in DOS/Windows as the FAT file system is case insensitive and it won't work (don't know about NTFS.)

The variable $File::Find::name contains the complete path of the file
including the directory name so if any of the directory names have upper case
letters then you are trying to move the files to a directory that does not
exist.  You should just convert the file names to lower case.

sub lowerCase {
    $oldName = $_;
    $newName = lc;
    print rename( $oldName, $newName ),
          qq( rename result: "$oldName" - "$newName"\n);
}



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to