Subscribe Add to Technorati Favorites

Wednesday, July 16, 2008

Collect files that were created/modified in last 30 to 60 minutes

I actually wrote this script in reply to a post.

This is what it does ...
Given a path (as command-line argument), the script will search through the file system & lists the files that were created/modified in last 30-60 minutes.

The script:

use strict;
use File::Find;

my $path_to_start = $ARGV[0];
my @files_bet_30_60 = ();
my $thirty_mins_in_secs = 30*60;
my $sixty_mins_in_secs = 60*60;

finddepth(\&wanted, $path_to_start);
foreach my $file (@files_bet_30_60) {
print "$file\n";
}

sub wanted {
my $file = $File::Find::name;
next unless (-f $file);

my $mtime = (stat($file))[9];
my $time_diff = time - $mtime;
push @files_bet_30_60, $file if
(($time_diff > $thirty_mins_in_secs) && ($time_diff < $sixty_mins_in_secs));
}

0 comments: