Ok, so I brought it here: I first get all the filenames into one text file and then I run the following, on the file:
use strict; use warnings; use Date::Parse; my @AoA_files=(); open IN, $ARGV[0]; while(<IN>) { my $infile=$_; chomp $infile; if($infile=~/^(\d+)\_(\d+)_(\d+)_(\d+)_(\d+)_(\d+)_(\d+)_(.*)/) { my $uid=$1; my $year=$2; my $month=$3; my $day=$4; my $hour=$5; my $minute=$6; my $second=$7; my $actual_filename=$8; my $timestamp = "$year-$month-$day"."T"."$hour:$minute:$second +"; if ( grep { $_->[1] eq $actual_filename } @AoA_files ) #if fil +ename exists, keep only the most recent one { #compare the timestamps my $existing_timestamp = $_->[0]; my $difference_in_seconds = str2time($timestamp) - str2tim +e($existing_timestamp); if($difference_in_seconds > 0) #current date is newer than + the one in the AoA - use this one { push @AoA_files, [ $timestamp, $actual_filename]; } } else #add it normally to the AoA { push @AoA_files, [ $timestamp, $actual_filename]; } } }
My idea here is to eventually create a second file with the full filenames that I need to keep. Does that make sense?

In reply to Re: Batch file renaming - on identical name, keep only most recent file, based on dates by Anonymous Monk
in thread Batch file renaming - on identical name, keep only most recent file, based on dates by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.