# loopdir.C for Pyroot

**URL:** <https://root-forum.cern.ch/t/loopdir-c-for-pyroot/27926>\
**Category:** ROOT\
**Created:** [February 14, 2018, 1:40am UTC](https://root-forum.cern.ch/t/loopdir-c-for-pyroot/27926 "2018-02-14T01:40:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![uperez25](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/uperez25/32/13779_2.png) [@uperez25](https://root-forum.cern.ch/u/uperez25)\
**Post date:** [February 14, 2018, 2:09am UTC](https://root-forum.cern.ch/t/loopdir-c-for-pyroot/27926/2 "2018-02-14T02:09:05Z")

</div>

Hi,

I think I got what I need from this link.

> [@Loop over all objects in a ROOT file](https://root-forum.cern.ch/t/loop-over-all-objects-in-a-root-file/10807/4):
>
> I just found this thread and thought I’d post an alternative, I think neater solution. All the intelligence is in the ~7 line getall function. I’ve not checked whether it’s particularly memory efficient since it runs perfectly fast for my current need, which is to just list ROOT all file contents… but being a generator it at least doesn’t try to put all the objects in memory at the same time! import ROOT def getall(d, basepath="/"): "Generator function to recurse into a ROOT file/dir and y…

Sharing it just in case google search leads people here.

Cheers,  
Uzzie

---

_[View the full topic](https://root-forum.cern.ch/t/loopdir-c-for-pyroot/27926)._
