Hello dear Monks,
I need to rename many files (~5,000) in a directory. They have the following structure:
8_2007_5_22_15_34_23_Table_-_2007522_XYZ_W3.pdf
and I need to strip off the first 7 numbers (userID and then year-month-day-hour-minute-second).
The challenge here is that some of them might actually have the same filename remaining after this operation, like the following example:
8_2007_5_22_15_34_23_Table_-_2007522_XYZ_W3.pdf
8_2007_5_22_22_34_12_Table_-_2007522_XYZ_W3.pdf
So, in this case, I would like to keep only the most recent one. To do this, I can use the following simple code I wrote:
use Date::Parse;
$file1 = '2019-3-25T14:40:22';
$file2 = '2019-6-12T22:34:8';
if (str2time( $file1 ) - str2time( $file2 ))
{
print "$file1 is more recent than $file2\n";
}
after transforming the dates into the above-mentioned command.
My problem is, how to go about finding and comparing the ones that actually have the same filename, after stripping out the unnecessary information from the beginning - so that I know which ones I need to compare.
any help will be greatly appreciated.
Thanks!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.