Re: reading a directory, first files the newest ones
- From: Gunnar Hjalmarsson <noreply@xxxxxxxxx>
- Date: Sun, 28 Oct 2007 03:02:34 +0100
jordilin wrote:
When I read a huge directory with opendir,
opendir(DIR,"dirname");
my $file;
while($file=readdir(DIR))
whatever...
it loads the oldest ones first. I would like the newest files first,
instead of the oldest. Taking into account that I am only interested
in the newest files, this takes a lot of time, as the directory is
really huge. I am talking about thousands and thousands of files. I
need to process the files that are two hours old from now. I am not
interested in those older than two hours ago.
Maybe you should let the system do the desired sorting. On *nix that might be:
chomp( my @files = qx(ls -t $dir) );
foreach my $file (@files) {
last if -M "$dir/$file" > 2/24;
print "$file\n";
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.
- Follow-Ups:
- Re: reading a directory, first files the newest ones
- From: jordilin
- Re: reading a directory, first files the newest ones
- References:
- reading a directory, first files the newest ones
- From: jordilin
- reading a directory, first files the newest ones
- Prev by Date: Re: reading a directory, first files the newest ones
- Next by Date: Re: reading a directory, first files the newest ones
- Previous by thread: Re: reading a directory, first files the newest ones
- Next by thread: Re: reading a directory, first files the newest ones
- Index(es):
Relevant Pages
|