Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided
I’ve written the following code, which is supposed to list all the files in a directory:
const char* inDir = “/path/to/directory/I/want/to/list”;
const char* ext = “.myextension”;
char* dir = gSystem->ExpandPathName(inDir);
void* dirp = gSystem->OpenDirectory(dir);
const char* entry;
const char* filename[100];
Int_t n = 0;
TString str;
while((entry) = (char*)gSystem->GetDirEntry(dirp))){
str = entry;
if(str.EndsWith(ext)){
filename[n++] = gSystem->ConcatFileName(dir, entry);
}
}
for (Int_t i = 0; i < n; i++){
Printf(filename[i]);
}
It works excellent when I set the directory path to %ROOTSYS%/tutorials (the path to the ROOT tutorials) and the extension to “.C”. It lists all the files in the ROOT tutorials. But when I try to list the files in the directory:
/disk/data/path/to/the/files
None of the files appear. I know they’re there, and I can access the directory via the terminal by using cd /path/to/the/directory and list all the files using .ls. I’ve also tried omitting the part of the code that checks for the extension.
This is the directory of my macro:
/disk/home/username/root-codes/mymacro.C
What am I doing wrong?