Re: reading a directory, first files the newest ones



On Oct 28, 1:36 am, Gunnar Hjalmarsson <nore...@xxxxxxxxx> wrote:
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,

How much time is that?

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.

You may want to use grep() to assign to an array the files you are
interested in.

my @files = grep -M $_ <= 2/24, readdir DIR;

--
Gunnar Hjalmarsson
Email:http://www.gunnar.cc/cgi-bin/contact.pl

To grab the files that are from two hours ago till now, I have to
process each file to check the modification time. Obviously, if the
while checks the oldest files first, it can take more than 10 minutes
to arrive for those files I am interested in. This directory has a
huge amount of files.

.



Relevant Pages