Re: reading a directory, first files the newest ones



On Oct 28, 2:02 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, 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

With this code, and taking into account that the directory is huge,
memory usage would be a problem as we are going to use a huge array
@files, and the Unix server is a very important one. Don't know if
that could be achieved by means of a while. The real problem is having
to process many files before arriving to the interesting ones. The
solution would be reading the newest ones first. I think there is no
solution. We have, either to slurp all the files into an array (which
is going to take time and memory), or process the whole directory
through a while (one file at a time) till we get the proper files,
which in this case is going to take a lot of time as well.

.



Relevant Pages

  • Data Load Query
    ... it into a MS SQL database. ... array that can vary between 1 to 50. ... Account Number ... which has a link to the customer information file. ...
    (comp.databases.ms-sqlserver)
  • Re: complicated array
    ... > the columns are account name and amount of order. ... > I need the section where this array would be to look as ... > could refer to that cell to understand its associated ...
    (microsoft.public.excel.worksheet.functions)
  • Using Objects as Arrays
    ... When I do this, it creates an array of 3 records; ... Dim accounts(50) As Account 'bankAcct is an object of class Account ... Now that I have the array, I want to get the balance based on what was ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Help with Array
    ... storage. ... length lists. ... For your account list case, ... If you're using an array to model a list of fixed-length it's possible ...
    (comp.lang.java.programmer)
  • Re: losing rows when sorting in excel
    ... >Look for discontiguous row numbers in the row header, ... >> other) just seem to disappear. ... So, it's a real problem ... >> something specifically with their account. ...
    (microsoft.public.excel.misc)