# How to split subdirectories into different root files?

**URL:** <https://root-forum.cern.ch/t/how-to-split-subdirectories-into-different-root-files/42705>\
**Category:** Newbie\
**Created:** [December 12, 2020, 10:36am UTC](https://root-forum.cern.ch/t/how-to-split-subdirectories-into-different-root-files/42705 "2020-12-12T10:36:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dongjokim](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dongjokim/32/24291_2.png) [@dongjokim](https://root-forum.cern.ch/u/dongjokim)\
**Post date:** [December 12, 2020, 10:36am UTC](https://root-forum.cern.ch/t/how-to-split-subdirectories-into-different-root-files/42705/1 "2020-12-12T10:36:52Z")

</div>

Hello,

I have a root file which contains 5 subdirectories. Each subdirectory also consist of few directories and many histograms are in each directory.

I want to make each directory into a separate root file, of course subdirectories should belong to the top directory.

Does this kind of class exist already somewhere?

Regards,

DongJo

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [December 14, 2020, 12:25pm UTC](https://root-forum.cern.ch/t/how-to-split-subdirectories-into-different-root-files/42705/2 "2020-12-14T12:25:37Z")

</div>

Hi @dongjokim,  
and welcome to the ROOT forum!

I don’t think we have helper functions or helper structs for something like that. The command-line tool `rootcp` might be what you need: `rootcp 'source.root:subdir/*' dest.root` should work.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![dongjokim](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dongjokim/32/24291_2.png) [@dongjokim](https://root-forum.cern.ch/u/dongjokim)\
**Post date:** [December 15, 2020, 3:07pm UTC](https://root-forum.cern.ch/t/how-to-split-subdirectories-into-different-root-files/42705/3 "2020-12-15T15:07:16Z")

</div>

thanks for your answer and suggestion. I might try to make a script to do the job with rootcp since I have 2 or 3 subdirectories.

Cheers,

DongJo
