General discussion

Locked

perl

By rjsaulakh ·
i wanna access all logs file in a directory which are created on different dates , i want to get the logs file between specific period of dates and then process them . so please let me know how can i check the creation date to the logs , take the logs between the given period and the process them

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Martin Simons In reply to perl

try the following:

use Time::Local;

opendir(DIR, "/path/to/directory");

# convert date Midnight 3 Mar 04
$start_time = timelocal(0,0,0,3,2,2004);

# convert date Midnight 3 Mar 05
$end_time = timelocal(0,0,0,3,2,2005);

while ($name = readdir(DIR)) {
next if (-d "/path/to/directory/" . $name);
# get creation time
$time = (stat("/path/to/directory" . $name))[10];
if (($time >= $start_time) && ($time < $end_time)) {
# process file. This file was created on an after
# the first dateand before the second date.
}
}

closedir(DIR);

Back to Web Development Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums