in reply to Rename file
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).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Rename file
by sashawn (Initiate) on Apr 05, 2011 at 19:06 UTC |