Hi,
I use ROOT 5.16/00 on Windows. So I want to write a script, that allows me go straight to directory (without opening new TBrowser) where I’ll be able to run two scripts, which I already have: one of them converter .dat files to .root, another draw histograms.
Thank you!
Something like this?
void change_dir(const char *dir, const char *macro1, const char *macro2)
{
TString file1(macro1), file2(macro2);
gSystem->ChangeDirectory(dir);
std::cout << "Directory changed to " << gSystem->WorkingDirectory() << std::endl;
if (gSystem->FindFile(".", file1)) {
std::cout << "Running " << macro1 << std::endl;
gInterpreter->ExecuteMacro(macro1);
}
if (gSystem->FindFile(".", file2)) {
std::cout << "Running " << macro2 << std::endl;
gInterpreter->ExecuteMacro(macro2);
}
}
Here is the output:
C:\Users\bellenot\rootdev>root -l
root [0] .x change_dir.C("Forum/testing", "macro1.C", "macro2.C")
Directory changed to C:\Users\bellenot\rootdev\Forum\testing
Running macro1.C
This is macro1...
Running macro2.C
This is macro2...
root [1]
Thank you very much! It works. One question how can I return back to previous path? I wrote gROOT->cd(); but it doesn’t work.
void change_dir(const char *dir, const char *macro1, const char *macro2)
{
TString file1(macro1), file2(macro2);
std::string olddir(gSystem->WorkingDirectory());
gSystem->ChangeDirectory(dir);
std::cout << "Directory changed to " << gSystem->WorkingDirectory() << std::endl;
if (gSystem->FindFile(".", file1)) {
std::cout << "Running " << macro1 << std::endl;
gInterpreter->ExecuteMacro(macro1);
}
if (gSystem->FindFile(".", file2)) {
std::cout << "Running " << macro2 << std::endl;
gInterpreter->ExecuteMacro(macro2);
}
gSystem->ChangeDirectory(olddir.c_str());
std::cout << "Directory changed to " << gSystem->WorkingDirectory() << std::endl;
}
I don’t know what I would do without you:)
Thanks a lot!
1 Like