I am looking for a way to check whether a directory in a TFile exists.
I see that interactively I can do:
z=_file0->cd(“analyzeHiMassTau”);
And z will become a boolean indicating whether the cd was successful or not. This doesn’t work within my script and nonetheless, I am sure that there is a better way to do check whether a directory exists.
Any suggestions would be greatly appreciated. Thanks!
Will
Thanks for the reply. I don’t see exactly how to use TDirectory::GetDirectory to get a boolean for whether or not the directory exists. Interactively I see that root returns the place in memory if the directory does exist:
The following should work:if (_file0->GetDirectory("analyzeHiMassTau")) {
// or if (_file0->GetDirectory("analyzeHiMassTau") != 0)
z=_file0->cd("analyzeHiMassTau");
}or even more directly:TDirectory *dir = _file0->GetDirectory("analyzeHiMassTau");
if (dir) {
dir->cd();
} else {
fprintf(stderr,"Missing directory analyzeHiMassTau\n");
}
Cheers,
Philippe.
[quote]I can’t tell if the printError option might be useful:[/quote]Why not?