Re: can I use findfirst - findnex for file search and collection?

From: Christian Holm Christensen <cholm_at_nbi.dk>
Date: Fri, 31 Mar 2006 20:11:32 +0200


Hi Anton,

On Fri, 2006-03-31 at 19:16 +0300, Anton Korneev wrote:
> Hello, dear rooters :),
>
> My task is prepare a list of files in specified directory by macro for
> ROOT interpretator (CINT).
> Does the ROOT has some functions for searching of files? I mean
> something like findfirst() findnext() routines in <dir.h>, which
> standart for dos and windows?
> Can you help me?

I think by far the simplest thing to do is

  TSystemDirectory dir(".", ".");
  TList* files = dir.GetListOfFiles();   files.Sort(); // Sort the files according to name   TIter next(files);
  TSystemFile* file = 0;
  while ((file = static_cast<TSystemFile*>(next()))) {     if (file->IsDirectory()) continue; // Ignore directories     TString fname(file->GetName());
    if (fname.EndsWith(".root")) {
      // Process ROOT file
    }
  }

This is independent of the underlying file-system, and could also work with ROOT file servers, provided you give the right URL:

  TSystemDirectory dir(".", "rootd://localhost/")   TSystemDirectory dir(".", "castor://cern.ch/user/f/foo/")

Abstractions are good! :-)

Yours,

-- 
 ___  |  Christian Holm Christensen 
  |_| |  -------------------------------------------------------------
    | |  Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
     _|           DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
    _|            Denmark                    Office: (+45) 353  25 404
 ____|   Email:   cholm_at_nbi.dk               Web:    www.nbi.dk/~cholm
 | |
Received on Fri Mar 31 2006 - 20:11:33 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:58 MET