wiso
May 11, 2012, 4:50pm
1
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());
}
wiso
May 11, 2012, 11:16pm
3
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.
wiso
May 12, 2012, 9:50am
5
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.