# TFile "RECREATE" gives error

**URL:** <https://root-forum.cern.ch/t/tfile-recreate-gives-error/35573>\
**Category:** Newbie\
**Tags:** root\
**Created:** [August 8, 2019, 4:31pm UTC](https://root-forum.cern.ch/t/tfile-recreate-gives-error/35573 "2019-08-08T16:31:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stzanos](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/stzanos/32/19538_2.png) [@stzanos](https://root-forum.cern.ch/u/stzanos)\
**Post date:** [August 8, 2019, 4:31pm UTC](https://root-forum.cern.ch/t/tfile-recreate-gives-error/35573/1 "2019-08-08T16:31:36Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 8, 2019, 6:01pm UTC](https://root-forum.cern.ch/t/tfile-recreate-gives-error/35573/2 "2019-08-08T18:01:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stzanos](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/stzanos/32/19538_2.png) [@stzanos](https://root-forum.cern.ch/u/stzanos)\
**Post date:** [August 8, 2019, 7:55pm UTC](https://root-forum.cern.ch/t/tfile-recreate-gives-error/35573/3 "2019-08-08T19:55:32Z")

</div>

Damnit windows,

Thanks bellenot
