TFile "RECREATE" gives error

Hello there people of Root,

I’m trying to use the “RECREATE” option on a TFile that already exists. As documentation says:

If dirname does not exist, it is created (like in “new”). If dirname already exist, all existing files in dirname are deleted before creating the new files.

I’m creating a TFile for which I keep changing the code and I want to run it over and over again for some tests and it’s really irritating that I have to delete the rootfile manually everytime before I can run the script again. This is the error:

SysError in <TFile::TFile>: could not delete SM1_20MNMMMS100008_FROM_2019_07_15_17_30_00_TO_2019_07_16_16_18_57.root (errno: 13) (Permission denied)

I also tried running root as an administrator but with no luck.

Extra information:

  • The rootfile has directories and tgraphs stored inside
  • Im using root 5.34/36 on windows 10
  • I run: TFile* plotfile = new TFile((data_timestamp + “.root”).c_str(), “RECREATE”);

Thanks in advance, I’m really baffled as to what is happening

On Windows, you cannot delete or recreate a file which is still in use (it s an OS limitation, and there is nothing we can do in ROOT). Try to delete the TFile pointer before to recreate it.

Damnit windows,

Thanks bellenot