Perl: Recursively rename all files and directories
Posted
by user305801
on Stack Overflow
See other posts from Stack Overflow
or by user305801
Published on 2010-03-31T23:28:41Z
Indexed on
2010/03/31
23:33 UTC
Read the original article
Hit count: 316
I need to recursively rename every file and directory. I convert spaces to underscores and make all file/directory names to lowercase. How can I make the following script rename all files in one run? Currently the script needs to be run several times before all the files/directories are converted. The code is below:
#!/usr/bin/perl
use File::Find;
$input_file_dir = $ARGV[0];
sub process_file {
$clean_name=lc($_);
$clean_name=~s/\s/_/g;
rename($_,$clean_name);
print "file/dir name: $clean_name\n";
}
find(\&process_file, $input_file_dir);
© Stack Overflow or respective owner