Your comments pretty much say it all
my $path = $opt_s . "\\*.*"; $path =~ s|\\|/|g; #find the newest file my $newestfile = (sort {(stat $b)[10] <=> (stat $a)[10]} glob $path)[0];
You are globbing over all files with extensions in $opt_s, and finding the newest. You need to restrict attention to those matching everything up to the extension in $opt_f. (Left as an exercise). I cringe a bit at re-invoking stat() for each comparison. If you simply read the $opt_s directory, and keep track of the latest file matching the $opt_f pre-extension, you can fix the problem and save a lot of stat()s. (Perhaps those are the only files you want to remove, too... hard to know from your description).
In reply to Re: Rename file
by jpl
in thread Rename file
by sashawn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |