How to get list of all files in directory

Hi,
Is there a way to get a list of all files in some directory using ROOT only?
I am working in Windows 7 using ROOT with Visual Studio 2010 Express.
Would appreciate any help!

Hi,

See for example this thread, or this macro:

void list_files(const char *dirname="C:/root/folder/", const char *ext=".root") { TSystemDirectory dir(dirname, dirname); TList *files = dir.GetListOfFiles(); if (files) { TSystemFile *file; TString fname; TIter next(files); while ((file=(TSystemFile*)next())) { fname = file->GetName(); if (!file->IsDirectory() && fname.EndsWith(ext)) { cout << fname.Data() << endl; } } } }
Cheers, Bertrand.

It works! Thank you!

Hello,
How could I open the file from this list?
Please help me.
Thank you.

Hello,
I am doing as follows:

FILE *fp;
//Open a data file in read-only mode
TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
dir.ReplaceAll(“Trial.c”,"");
dir.ReplaceAll("/./","/");

TString pwd(gSystem->pwd()); //Get a current directory
TSystemDirectory dire(dirname, dirname); //TSystemDirectory dir(directoy name, Path);
TList *files = dire.GetListOfFiles(); //Displays a list of all files
gSystem->cd(pwd.Data());

if (files) {
TSystemFile file; //TSystemFile class is internally used by the TBrowser to represent files.
TString fname;
TIter next(files);
while ( (file = (TSystemFile
)next()) ) { //Iterating over a loop
fname = file->GetName();
if ( !(file->IsDirectory()) &&
(!prefix || !(*prefix) || fname.BeginsWith(prefix)) &&
(!suffix || !(*suffix) || fname.EndsWith(suffix)) ) {
//cout << fname.Data() << endl;
}
}
}
delete files;

fp = fopen(Form(“fname.Data()”,dir.Data()),“r”);

But its not working either.

Any sugessions are welcome.

Thank you.

Hi,

Did you resolve this issue?

Philippe.