Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

filemod

by neuroball (Pilgrim)
on Dec 31, 2003 at 20:10 UTC ( [id://317987]=sourcecode: print w/replies, xml ) Need Help??
Category: Utility Scripts
Author/Contact Info neuroball, who can be reached at neuroball@usa.net.
Description: Small script that recursively searches the specified or current working directory for files with a modified timestamp in a specified date/time range.

Update: Detabed source code.

#!/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";
}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://317987]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-11-03 03:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    chatterbot is...






    Results (13 votes). Check out past polls.