John,

Thanks for the script. I need to filter the result by a specific file
extension, how do I that? I tried,

    ( not exists $files{ $dir } or $files{ $dir }{ mtime } > -M _ )
      and ( @{ $files{ $dir } }{ qw/name mtime/ } = ( $name, -M _ ) )
      and ( /^(full)\w*(\.db)$/ )

It does not seem to work. Actually I would be grateful if you could also
help me understand how the script works. I cannot figure out the what role _
plays. I know -M is "Script start time minus file modification time, in
days".

Thanks

Rajesh

> -----Original Message-----
> From: John W. Krahn [mailto:[EMAIL PROTECTED]
> Sent: Friday, March 26, 2004 1:24 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Search for a file pattern in a directory tree recursively
> 
> 
> Rajesh Dorairajan wrote:
> > 
> > Hello All,
> 
> Hello,
> 
> > I went through all the documentation and previous mail posts about
> > File::Find and finally decided I needed some help.
> > 
> > I've a directory structure I need to parse. The directory contains
> > subdirectories with filenames such as
> > 
> > full094382.db
> > full483292.db
> > 
> > Now, I need to parse through each subdirectory and pick up 
> the name of the
> > file that was MODIFIED MOST RECENTLY. I do have a sort of a 
> code to start
> > with.
> > 
> > use strict;
> > use warnings;
> > 
> > $\ = "\n";
> > 
> > use File::Find;
> > 
> > my $localdir = 'C:/docs';
> > my @files;
> > 
> > find(
> >   sub { push ( @fullcrls, $File::Find::name ) if 
> /^(full)\w*(\.db)$/ },
> >   $localdir );
> > 
> > foreach ( @fullcrls ) {
> >     print;
> > }
> > 
> > However, I am not able to figure how to filter out the 
> repeat entries in a
> > sub-directory such as
> > 
> > C:/docs/dir1/full094382.db
> > C:/docs/dir1/full483292.db
> > C:/docs/dir2/full482952.db
> > C:/docs/dir2/full930284.db
> > 
> > In the above example, I need only need filename from dir1 
> and dir2 that was
> > last modified. Is there a way to do this filtration in the 
> find( sub {} )
> > above?
> 
> This should do what you want:
> 
> use strict;
> use warnings;
> use File::Find;
> use vars qw( $dir $name );
> *dir  = *File::Find::dir;
> *name = *File::Find::name;
> 
> my $localdir = 'C:/docs';
> my %files;
> 
> find(
>   sub {
>     return unless -f;
>     ( not exists $files{ $dir } or $files{ $dir }{ mtime } > -M _ )
>       and ( @{ $files{ $dir } }{ qw/name mtime/ } = ( $name, -M _ ) )
>     }, $localdir
>   );
> 
> for my $entry ( values %files ) {
>   print $entry->{ name }, "\n";
>   }
> 
> __END__
> 
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 

Reply via email to