Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
This code works great, but when I run it I can see the changes but when I look inside of the diretory the files aren't changing, any explanation for it?
Thank you!

#!/perl/bin/perl -w use strict; # Open 'find' process to list files recursively with paths #my $path_to_dir = shift; print "Opening Directory\n"; my $path_to_dir = "c:/progra~1/apache~1/apache2/htdocs/test"; dir("$path_to_dir"); sub dir { opendir(DIR,"$_[0]"); my @list_of_files = readdir(DIR); foreach(@list_of_files) { print "BEFORE: $_\n"; if($_ ne "." && $_ ne "..") { if(-d "$_[0]/$_") { dir("$_[0]/$_"); } else { $_ =~ s/\ /_/ig; rename "$_[0]/$_","$_[0]/\L$_"; print "AFTER: $_[0]/$_,$_[0]/\L$_\n\n"; } } } } ##### print "\n\nDone!... ;-)";

Replies are listed 'Best First'.
Re: Renaming Not Working
by davido (Cardinal) on Aug 18, 2005 at 15:51 UTC

    It is failing silently because you're not checking the return value from rename... so you're never seeing the failure reported.

    Try this:

    rename "$_[0]/$_", "$_[0]/\L$_" or die "Couldn't rename:\n$!\n";

    The error message (stored in $!) will give you some insight into why it's failing. See also die.


    Dave

Re: Renaming Not Working
by duff (Parson) on Aug 18, 2005 at 15:50 UTC

    I'd imagine that the problem is that you're on a Windows system which isn't as sensitive to the case of letters in filenames as it should be.

    Also, it looks like you should be using File::Find

      There seems to be a lot of intrest in File::Find lately!
      use File::Find; find (sub {rename $_, lc $_ }, @ARGV);
Re: Renaming Not Working
by NateTut (Deacon) on Aug 18, 2005 at 15:53 UTC
    It may also be that you need to "refresh the view" in Windoze Explorer if that's what you're using.