How do I use File::Copy to rename a file extension?
So far, I can add an extension. I need to replace the file extension instead.
Example:
myfilename.txt to myfilename.dat
My code:
use strict;
use warnings;
use File::Copy;
my ($oldfn) = qw (myfilename.txt);
my $newfn = $oldfn . ".dat";
rename($oldfn, $newfn)
or die("Can't rename: $!\n");
Result: myfilename.txt.dat
Use File::Basename’s fileparse method to find the suffix, then do a search/replace.
Output: