Clone and rename a .root File

Hi guys,

I need your help. So my problem is let say I have a file called Newstar.root

How to clone Newstar.root into a file called Newstar01.root

I tried with TFile::Clone(“Newstar.root”, newname=“Newstar01.root”) but somehow it doesn’t work

Thankyou in advance

Best Regards,

Simply copy one file to another file (with another name) using your standard operating system commands.

Thankyou Wile. I am using ubuntu.

But I want to put it in a macro so I can run it with loop and TString command, so I hope it isnpossible to clone usinh root command.

See: TSystem Class Reference

  TString cmd = "cp Newstar.root Newstar01.root";
  std::cout << "cmd exit status = " << gSystem->Exec(cmd) << std::endl;
1 Like

I’ve tried it an it worked. Thankyou very much

Here is the modified code:
printf(“Input Space Multiplicity = “);
scanf(”%d”, &multip);
TString cpCMD;
cpCMD = TString::Format(“cp Newstar.root ./result/DataNewStar%d.root”,multip);
std::cout << “cmd exit status = " << gSystem->Exec(cpCMD) << std::endl;
printf(”\nDone Cloning\n");

Thankyou thankyou and thanks again!

Best Regards,

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