Terry Vaughn wrote: > Hello. Can someone fwd me a snibbet of code to identify all files within a >specified unix directory with a specific create date so that only those files are >opened and operated on. Thanks.
This can be packed into tighter code (doing most of the work with a grep on readdir), but it's easier to follow if broken out: use strict; use Time::Local; # replace local with gm on these calls if you want GMT rather than local time my $delta = 86400 * 1; # use yesterday for example my @t = localtime(time - $delta); # get local epoch time for the day $t[0] = 0; $t[1] = 0; $t[2] = 0; # drop back to midnight (remove H:M:S) my $start = timelocal (@t); $t[3]++; # add a day so we get all files from the day in question my $end = timelocal (@t); my $dir = 'C:/tmp'; opendir DIR, $dir; my @files = readdir DIR; closedir DIR; print "$start => $end\n"; foreach (@files) { print "$_\n"; next if -d "$dir/$_"; # skip dirs my $ftime = (stat _)[10]; # get epoch creation time # you may really want last modification time: # my $ftime = (stat _)[9]; # get epoch last modification time next if $ftime < $start; # skip older than start time next if $ftime > $end; # skip newer than end time print "$_\n"; } __END__ -- ,-/- __ _ _ $Bill Luebkert ICQ=162126130 (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl) -/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/ _______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs