# Loop over subdirectories of a rootfile in pyRoot

**URL:** <https://root-forum.cern.ch/t/loop-over-subdirectories-of-a-rootfile-in-pyroot/32666>\
**Category:** Newbie\
**Created:** [February 9, 2019, 2:22pm UTC](https://root-forum.cern.ch/t/loop-over-subdirectories-of-a-rootfile-in-pyroot/32666 "2019-02-09T14:22:05Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [February 12, 2019, 11:17am UTC](https://root-forum.cern.ch/t/loop-over-subdirectories-of-a-rootfile-in-pyroot/32666/2 "2019-02-12T11:17:25Z")

</div>

Hello,  
Can you check if the final solution discussed here works for you?

> [@Loop over all objects in a ROOT file](https://root-forum.cern.ch/t/loop-over-all-objects-in-a-root-file/10807/5):
>
> Since I found both replies being broken in my case. In particular, IsFolder() returns True for TTree, GetListOfKeys() chokes with TTree, etc, so pasting my longer solution here: import ROOT def Map(tf, browsable\_to, tpath=None): """ Maps objets as dict[obj\_name][0] using a TFile (tf) and TObject to browse. """ m = {} for k in browsable\_to.GetListOfKeys(): n = k.GetName() if tpath == None: m[n] = [tf.Get(n)] else: m[n] = [tf.Ge…

Cheers,  
Enric

---

_[View the full topic](https://root-forum.cern.ch/t/loop-over-subdirectories-of-a-rootfile-in-pyroot/32666)._
