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!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|