Is it possible to create a directory with ROOT inside root-macro?

Suppose I have a file that contains list (array) of names. Then I want to create folders those names are names in that list in a loop. Something like this:

for (Int_t i = 0; i < (Int_t)list.size(); i++){
  //create a directory with name list[i];

You can execute system commands using gSystem. To create a directory (on linux) do:

gSystem->Exec("mkdir my_folder");

You can also use the system’s function mkdir(). Here is an excerpt from man 3 mkdir:

       mkdir, mkdirat -- make a directory relative to directory file descriptor

       #include <sys/stat.h>

       int mkdir(const char *path, mode_t mode);
       int mkdirat(int fd, const char *path, mode_t mode);
1 Like

Yes but that does not directly work from the ROOT prompt. Whereas my solution does:

root [1] mkdir("aaa")
input_line_15:2:3: error: use of undeclared identifier 'mkdir'
root [2] gSystem->Exec("mkdir aaa");
root [3] 

It works if you include the header:

$ root -l
root [0] #include <sys/stat.h>
root [1] mkdir("foo", S_IRWXU);
root [2] 

Ok :slight_smile: ! still two lines instead of one :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.