Re: reading a directory, first files the newest ones



jordilin <jordilin@xxxxxxxxx> 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.

That is completely up to your OS and your file system. Perl just provides
a fairly simple conduit for their behavior to reach you.

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. I know that because I
check the modification time with stat.
any idea?

Come up with a better directory structure; one that doesn't involve keeping
thousands and thousands of file in one directory that has to be scanned
over and over again. Or make whatever puts the files into that directory
to make a log, or to also create a symbolic link in another directory
pointing to the new file, which link can be deleted after 2 hours or so.

Its possible that your OS and your file system provide other tools for
inspecting very large directories more efficiently, but I rather doubt it.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
.



Relevant Pages

  • Re: reading a directory, first files the newest ones
    ... jordilin wrote: ... To grab the files that are from two hours ago till now, ... process each file to check the modification time. ... while checks the oldest files first, it can take more than 10 minutes ...
    (comp.lang.perl.misc)
  • Re: reading a directory, first files the newest ones
    ... it loads the oldest ones first. ... I would like the newest files first, ... Taking into account that I am only interested ... check the modification time with stat. ...
    (comp.lang.perl.misc)
  • reading a directory, first files the newest ones
    ... When I read a huge directory with opendir, ... it loads the oldest ones first. ... I would like the newest files first, ... check the modification time with stat. ...
    (comp.lang.perl.misc)
  • Re: reading a directory, first files the newest ones
    ... process each file to check the modification time. ... while checks the oldest files first, it can take more than 10 minutes ... Yeah, it seems that this would be a solution. ...
    (comp.lang.perl.misc)