Perl: Recursively rename all files and directories
- by user305801
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);