# Loop over all objects in a ROOT file

**URL:** <https://root-forum.cern.ch/t/loop-over-all-objects-in-a-root-file/10807>\
**Category:** ROOT\
**Created:** [August 20, 2010, 11:28am UTC](https://root-forum.cern.ch/t/loop-over-all-objects-in-a-root-file/10807 "2010-08-20T11:28:32Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![rmbianchi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rmbianchi](https://root-forum.cern.ch/u/rmbianchi)\
**Post date:** [August 20, 2010, 11:28am UTC](https://root-forum.cern.ch/t/loop-over-all-objects-in-a-root-file/10807/1 "2010-08-20T11:28:32Z")

</div>

After having looked for a hint in the forum, I found this thread  
[http://root.cern.ch/phpBB3//viewtopic.php?f=3&t=7246&p=30333](http://root.cern.ch/phpBB3//viewtopic.php?f=3&t=7246&p=30333)

Here I post my version of the small pyroot function, where you can specify a folder path inside the ROOT file.

```auto
def GetKeyNames( self, dir = "" ):
        self.cd(dir)
        return [key.GetName() for key in gDirectory.GetListOfKeys()]
TFile.GetKeyNames = GetKeyNames

keyList = f.GetKeyNames(internalPath)
print "\nKeys in file:", keyList

```

I post it here, with an explicit subject, since it might be useful to other users as well.

Cheers,

Ric.

---

_[View the full topic](https://root-forum.cern.ch/t/loop-over-all-objects-in-a-root-file/10807)._
