TSystemDirectory::GetListOfFile null pointer

It happens (ROOT 5.30/06) that if a call TSystemDirectory::GetListOfFile twice the second time I got 0. Example

TSystemDirectory directory("existing_directory", "existing_directory");
directory.GetListOfFile();
directory.GetListOfFile(); // returns 0 !!!

Two brutal fixes … either … use “absolute paths” … /The/Absolute/Path/Of/My/existing_directory : { TString pwd(gSystem->pwd()); TString abspath = pwd + "/"; abspath += "existing_directory"; TSystemDirectory directory(abspath.Data(), abspath.Data()); TList *l; l = directory.GetListOfFiles(); if (l) {l->Print(); delete l;} l = directory.GetListOfFiles(); if (l) {l->Print(); delete l;} l = directory.GetListOfFiles(); if (l) {l->Print(); delete l;} gSystem->cd(pwd.Data()); } … or … use “relative paths” … existing_directory : { TString pwd(gSystem->pwd()); TSystemDirectory directory("existing_directory", "existing_directory"); TList *l; l = directory.GetListOfFiles(); if (l) {l->Print(); delete l;} gSystem->cd(pwd.Data()); l = directory.GetListOfFiles(); if (l) {l->Print(); delete l;} gSystem->cd(pwd.Data()); l = directory.GetListOfFiles(); if (l) {l->Print(); delete l;} gSystem->cd(pwd.Data()); }

Thank you, at the end I prefer to save the list one time and reuse it

I hope you noticed in my source code that the call to “directory.GetListOfFiles()” changes the “current/working directory” to the “existing_directory” (and that’s why the second call was failing in your case) so one needs to “restore” the old one afterwards.

ok, now I understand the problem. By the way: is this feature good/needed?

Hi,

This issue has been resolved in v5.34/00 and above.

Cheers,
Philippe.