# Delete TFile doesn't work. SysError in \<TFile::TFile\>: file ~~.root can not be opened for reading (Too many open files)

**URL:** <https://root-forum.cern.ch/t/delete-tfile-doesnt-work-syserror-in-tfile-tfile-file-root-can-not-be-opened-for-reading-too-many-open-files/34429>\
**Category:** ROOT\
**Created:** [June 5, 2019, 5:57am UTC](https://root-forum.cern.ch/t/delete-tfile-doesnt-work-syserror-in-tfile-tfile-file-root-can-not-be-opened-for-reading-too-many-open-files/34429 "2019-06-05T05:57:52Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![SJLPHI](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/e480ec/32.png) [@SJLPHI](https://root-forum.cern.ch/u/SJLPHI)\
**Post date:** [June 15, 2019, 7:51am UTC](https://root-forum.cern.ch/t/delete-tfile-doesnt-work-syserror-in-tfile-tfile-file-root-can-not-be-opened-for-reading-too-many-open-files/34429/11 "2019-06-15T07:51:23Z")

</div>

Question from this post:

> [@Too many open files](https://root-forum.cern.ch/t/too-many-open-files/9237):
>
> Dear Rooters, I am writing a macro where I wish to read histograms from 1000 files and add them together. I open each file at the time in a loop using: TFile \*myFile = new TFile(); myFile-\>Open(fileName,“read”); From the file I copy two histograms (I don’t think this is relevant but) using the ROOT feature that whenever a file is opened you automatically enter this file: h\_Ptmp = new TH1F(\*h\_primaryElectronFluenceSpectrum); h\_Stmp = new TH1F(\*h\_scatterElectronFluenceSpectrum); Finally I c…

How did TH1::AddDirectory(kFALSE) help?  
Furthermore,  
TFile \*file = TFile::Open(filename.c\_str());  
yields segment fault whereas  
file = new TFile( filename.c\_str() , “read”);  
does not, if the root file exists. The constructor gives me a chance to check for null pointer before crashing.

---

_[View the full topic](https://root-forum.cern.ch/t/delete-tfile-doesnt-work-syserror-in-tfile-tfile-file-root-can-not-be-opened-for-reading-too-many-open-files/34429)._
