The TChain::Add function doesn’t do globbing, but loops over all files in the specified directory and tries to match them. So no wildcards allowed for directories (wildcards are not even allowed for all types of filesystems). Documentation says Wildcard treatment is triggered by the any of the special characters []*? which may be used in the file name
So you need to loop all by yourself.
With ROOT:
auto dir = gSystem->OpenDirectory("main_dir");
while (auto f = gSystem->GetDirEntry(dir)) {
if (!strcmp(file,".") || !strcmp(file,"..")) continue;
chain->Add(TString("main_dir/") + f + "/*.root");
}
gSystem->FreeDirectory(dir);
Or you can use globbing:
#include <glob.h>
std::vector<std::string> glob(const char *pattern) {
glob_t g;
glob(pattern, GLOB_TILDE, nullptr, &g); // one should ensure glob returns 0!
std::vector<std::string> filelist;
filelist.reserve(g.gl_pathc);
for (size_t i = 0; i < g.gl_pathc; ++i) {
filelist.emplace_back(g.gl_pathv[i]);
}
globfree(&g);
return filelist;
}
for (const auto &filename : glob("path/to/main_directory/*/*.root")) {
chain->Add(filename.c_str());
}