I ran into the same thing. What I had to do is run a system command for a dir to a txt file. Then open the txt file and look at the date. I also had to format localtime to a MSDOS readable date/time. For Instance I created a perl script to check Backup Exec log files based on date.

Code to Acquire the NT MS-DOS Readable Date
# Acquire the Local Time Array ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time +); # Convert less the "10" so they equal a two char date. $Month = $mon + "1"; if ($month < "10"){ $Month = '0' . "$Month"; } if ($mday < "10"){ $mday = '0' . "$mday"; } # Get the last two digits of a year, the way DOS sees file names. $RealYear = substr($year, 1); # This created $TimeStampDate into a format found in a DIR command in +DOS. Ex. 03/28/01. $TimeStampDate = "$Month". "/". "$mday" . "/" . "$RealYear";

Sub to create the cmd file to run,a nd run it.
sub CreateCmdFile { $FileName = 'D:\\Perl\\pl\\Check\\' . "$CurrentServerName" . ' +.cmd'; unlink($FileName); open(servercmd, "> $FileName"); print servercmd '@echo off' . "\n"; $VeritasLocation = '"\\\\' . "$CurrentServerName" . '\\C$\\Pro +gram Files\\Veritas\\Backup Exec\\NT\\Data\\*.txt"'; print servercmd 'dir ' . "$VeritasLocation" . ' > D:\\Perl\\pl +\\Check\\' . "$CurrentServerName" . '.txt'; close(servercmd); system("$FileName"); }

Finally to check the .txt file vs. the date.
sub FindMatchingDates { $ServerDirectoryFile = 'D:\\Perl\\pl\\Check\\' . "$CurrentServ +erName" . '.txt'; open(logfilelisting, "$ServerDirectoryFile") or die "Unable to + open file: $!"; @CheckForMatchingDate = <logfilelisting>; close(logfilelisting); foreach (@CheckForMatchingDate) { $SubOfCheckForMatchingDate = substr($_, 0, 8); if ($SubOfCheckForMatchingDate eq $TimeStampDate){ $AssignedCorrectLogFile = substr($_, 39); chomp($AssignedCorrectLogFile); push(@CorrectLogFiles, "$AssignedCorrectLogFil +e"); $LogFileFound = "1"; } } }

So in this case it pushes the Matching File name to @CorrectLogFile which can be used later.
Sgt

In reply to Re: How do I pick one file from a directory based on the file date? by SgtClueLs
in thread How do I pick one file from a directory based on the file date? 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.