[Canberra-pm] Most efficient way to find the ISO 8602 date of athe most recently modifiec file in a directory

John.Hockaday at ga.gov.au John.Hockaday at ga.gov.au
Wed May 3 23:54:10 PDT 2006


Thanks to everyone who provided solutions.  I took the first one that had
code in it.  Here is what I used:

############################################################
#!/usr/local/bin/perl
#####################
# Checks to see if we can get the date of the last file in a directory.
#####################
use strict;
use Date::Manip;
  
  my ($fileDir) = "/public/http/www/docs/meta";
  my ($prefix) = "ga";

  opendir( DIRECTORY, "$fileDir" )
    or die "Can't open directory $fileDir: $! \n";
  my @entries   = grep {m/\A$prefix.*/} readdir DIRECTORY;
  closedir DIRECTORY;

  return undef if (scalar at entries == 0);

  my $newest = 0;
  foreach my $file (@entries) {
    $file = "$fileDir/$file";
    next if (!-f $file);
    my @stat = stat $file;
    if ($stat[9] > $newest) {
      $newest = $stat[9];
    }
  }

  my $date = &ParseDateString("epoch $newest");
  print &UnixDate($date, "%Y-%m-%dT%H:%M:%S");

exit(0);
############################################################

Thanks again.  Great list.


John

> -----Original Message-----
> From: canberra-pm-bounces+john.hockaday=ga.gov.au at pm.org 
> [mailto:canberra-pm-bounces+john.hockaday=ga.gov.au at pm.org] 
> On Behalf Of Michael James
> Sent: Thursday, 4 May 2006 12:02 PM
> To: canberra-pm at pm.org
> Subject: Re: [Canberra-pm] Most efficient way to find the ISO 
> 8602 date of athe most recently modifiec file in a directory
> 
> 
> On Thu, 4 May 2006 11:41 am, John.Hockaday at ga.gov.au wrote:
> 
> > I am trying to find the date
> > of the most recently modified file in a directory.
> > I thought that someone should have done this already.
> > I have been looking into:
> > 
> > Date::Calc(Time_to_Date)
> > File::stat
> > localtime
> 
> > The output should be in ISO 8601 format.
> > IE, 2006-05-04T11:21:20
> 
> There is a good section on this in the perl Cookbook,
>  recipe 3.9 page 101.
> 
> 
> You Do have the Perl Cookbook don't you?
> The only question is whether you need a second copy,
>  it's a heavy book to carry around ...
> 
> Seriously though, If you can't lay your hands on one quickly,
>  I'll relay some of the goodness therein.
> 
> 
> -- 
> Michael James                         michael.james at csiro.au
> System Administrator                    voice:  02 6246 5040
> CSIRO Bioinformatics Facility             fax:  02 6246 5166
> 
> You Do have the Perl Cookbook don't you?
> The only question is whether you need a second copy,
>  it's a heavy book to carry home...
> 
> seriously though, If you can't lay your hands on one quickly,
>  I'll relay some of the goodness therein.
> _______________________________________________
> Canberra-pm mailing list
> Canberra-pm at pm.org
> http://mail.pm.org/mailman/listinfo/canberra-pm
> 


More information about the Canberra-pm mailing list