Browse/Parse physical directories


I have a (physical, real) directory on my linux system which contains different root and other files. What I would like to do, in a cint-compatible script, is the following bash loop:

for i in ls $dirname/myname*.root; do

do something with the file $i and the root classes in it

which requires root and cannot be done in bash


I could do it by redirecting the outstream, applying gSystem->Exec() and catching the output with a string etc, or piping the output to a temporary file, and reading that, or use boost/filesystem/operations.hpp, which seems to cause problems in cint, but this is all very ugly.

-> Is there an easier way using root classes (TDirectory or TFolder or such)? Or: How would you do this?

Thanks, Stefan

Hi Stefan,

Something like this?:

TSystemDirectory dir(dirname, path); TList *files = dir.GetListOfFiles(); if (files) { TIter next(files); TSystemFile *file; TString fname; while ((file=(TSystemFile*)next())) { fname = file->GetName(); if (!fname.EndsWith(".root")) continue; // do whatever you want with root file... } }