qsl has asked for the wisdom of the Perl Monks concerning the following question:

Great Monks,
I am having some files in a location of my remote machine,Uinsg Telnet I have to get the files created by today only and upto now.But the script is taking the files of yesterday and also it is not taking the file created upto now and taking files before created 2 hours back.Can anyone let me know how can i solve this issue. see the code below,But the remote server time is different from my local machine.
[Localmachine:]date Thu Jul 6 14:45:01 IST 2006 [Remotemachine:]date Thu Jul 6 10:14:09 IST 2006
see the code below I am using
@logfiles = $telnet->cmd("find . -mtime 0 -print"); foreach $logfile (@logfiles) { chomp($logfile); @contents = $telnet->cmd(qq(perl -MFile::stat -e 'print stat(s +hift)->mtime()' $logfile)); foreach $mtime (@contents) { chomp($mtime); $logtime = strftime( "%Y%m%d %H%M", localtime($mtime) +); }
As per the code,it should take all the files,upto till now.
Thanks.

Replies are listed 'Best First'.
Re: How to get the latest files in directory
by Anonymous Monk on Jul 06, 2006 at 11:52 UTC

    Your phrase files created by today only and upto now is poorly defined and as such, you didn't translate it well into code.

    First, calculate the epoch time for today's date, with hour, minute, second set to zero with Time::Local. This gives you the timestamp for today midnight.

    Then, simply numerically compare each file's timestamp with the midnight timestamp.