Web Development

General discussion



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.

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.


Related Discussions

Related Forums