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];
}
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
:
NAME
mkdir, mkdirat -- make a directory relative to directory file descriptor
SYNOPSIS
#include <sys/stat.h>
int mkdir(const char *path, mode_t mode);
int mkdirat(int fd, const char *path, mode_t mode);
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'
(mkdir("aaa"))
^
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 ! still two lines instead of one
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.