Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Batch file renaming - on identical name, keep only most recent file, based on dates

by Fletch (Bishop)
on Nov 05, 2019 at 14:12 UTC ( [id://11108323]=note: print w/replies, xml ) Need Help??


in reply to Batch file renaming - on identical name, keep only most recent file, based on dates

Handwaving fish.

my @candidate_files = obtain_candidates( ); ## File::Find::Rule, opend +ir/readdir, ... my %seen_files; my @to_delete; for my $file ( @candidate_files ) { ## regex out, use str2date, yadda yadda yadda my( $real_file, $date ) = parse_filename( $file ); if( not exists $seen_files{ $real_file } ) { $seen_files{ $real_file } = [ $file, $date ]; } else { my $prior_date = $seen_files{ $real_file }->[1]; if( $date - $prior_date > 0 ) { $seen_files{ $real_file } = [ $file, $date ]; } else { push @to_delete, $file; } } } process_deletions( @to_delete );

The cake is a lie.
The cake is a lie.
The cake is a lie.

  • Comment on Re: Batch file renaming - on identical name, keep only most recent file, based on dates
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11108323]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 12:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found