#!/usr/local/bin/perl
# filemod -- recursively scans the current or specified directory
# and returns files in a specified date/time range
use File::Find;
use Time::Local;
use Cwd;
sub checkDate
{
if ( my $date_to_check = shift )
{
if ( $date_to_check =~ m/^(\d+)\/(\d+)\/(\d{2,4})\s+(\d+):(\d+):(\
+d+)$/ )
{
my $date = {
month => $1 - 1, # Time::Local month starts with
+ zero
day => $2,
year => $3,
hour => $4,
minute => $5,
second => $6
};
return $date;
}
}
}
if ( my $date_after = checkDate( $ARGV[0] ) and
my $date_before = checkDate( $ARGV[1] ) )
{
my $after_epoch = timelocal( $$date_after{"second"},
$$date_after{"minute"},
$$date_after{"hour"},
$$date_after{"day"},
$$date_after{"month"},
$$date_after{"year"} );
my $before_epoch = timelocal( $$date_before{"second"},
$$date_before{"minute"},
$$date_before{"hour"},
$$date_before{"day"},
$$date_before{"month"},
$$date_before{"year"} );
find( \&isModifiedBetween, $ARGV[2] || getcwd );
sub isModifiedBetween
{
if (! -d $File::Find::name && -e)
{
my $file_epoch = (stat $File::Find::name)[9];
if ($file_epoch > $after_epoch and $file_epoch < $before_epoch )
{
my $file_time = localtime ($file_epoch);
print $file_time."\t".$File::Find::name."\n";
}
}
}
}
else
{
print "invalid token(s): [$ARGV[0]] / [$ARGV[1]]\n";
print "usage: filemod [start date/time] [end date/time] ([directory]
+)\n";
print "date/time format: \"MM/DD/YY HH:MM:SS\" or \"MM/DD/YYYY HH:MM
+:SS\"\n";
}
In reply to filemod
by neuroball
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.