I'm using this code to process my folders and files with two subs:
"sub folders" for folder names only
"sub files" for file names with extensions only
But I realized that "sub folders" messes with my files with extensions during the rename process.
How to distinguish the processes from one another or what is the intelligent way to tell "sub folders" to rename "names" with no extension and "sub files" to rename "names" with externsion?
find(\&folders, $dir_source);
sub folders {
my $fh = $File::Find::dir;
my $artist = (File::Spec->splitdir($fh))[3];
if (-d $fh) {
my $folder_name = $_;
# some substitution
rename $folder_name, $_;
}
}
find(\&files, $dir_source);
sub files {
/\.\w+$/ or return;
my $fn = $File::Find::name;
my ($genre, $artist, $boxset, $album, $disc);
if ($fn =~ /Singles/ or $fn =~ /Box Set/) {
($genre, $artist, $boxset, $album, $disc) = (File::Spec->splitdir($fn))[2..6];
}
else {
($genre, $artist, $album, $disc) = (File::Spec->splitdir($fn))[2..5];
}
if (-e $fn) {
my $file_name = $_;
# some substitution
rename $file_name, $_;
}
}