(Reading time: 1 minute)

We can use finddepth() in File::Find to recursively find files in a directory and do actions like renaming etc.

 

Here is a sample snippet:

 
use File::Find;
 
 
finddepth (\&depth, "D:\\");
 
 
sub depth { 
      my $old = $_;
      my $oldName = "newsample";
      my $newName = "sample";
      s/$oldName/$newName/ or return; # don't do anything if you don't have oldname
      -e and return; # don't rename over an existing file!
      rename $old, $_ or die "cannot rename $old to $_: $!";
    }
 
 
 

Oxygen
Author: Oxygen
Other articles by this author

Chillzee Tag Cloud

Let's Socialize

About Chillzee

Chillzee.com is an entrepreneurship portal.

The site provides informative topics on Organizational and Strategic needs.