How can I rename all files on a drive with .wma and .wmv extensions to .txt extension using Perl regardless how deep they are in the directory structure?
See perldoc File::Find. The examples in the documentation are pretty self-explanatory and will get you most of the way there. When you have an attempt, update the question with more information.
If this is a learning exercise, you will learn better by first trying to do yourself.
UPDATE:
Assuming you have had a chance to look into how to do this yourself and taking into account the fact that various solutions have been posted, I am posting how I would have done this. Note that I would choose to ignore files such as ".wmv": My regex requires something to come before the dot.
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
my ($dir) = @ARGV;
find( \&wanted, $dir );
sub wanted {
return unless -f;
return unless /^(.+)\.wm[av]$/i;
my $new = "$1.txt";
rename $_ => $new
or warn "'$_' => '$new' failed: $!\n";
return;
}
__END__
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With