# Save directory according to subject hierarchy

**URL:** https://discourse.slicer.org/t/save-directory-according-to-subject-hierarchy/20740
**Category:** Support
**Created:** [November 23, 2021, 5:21am UTC](https://discourse.slicer.org/t/save-directory-according-to-subject-hierarchy/20740 "2021-11-23T05:21:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Kanga](https://avatars.discourse-cdn.com/v4/letter/k/6bbea6/32.png) [@Kanga](https://discourse.slicer.org/u/Kanga)
#### Post date: [November 23, 2021, 5:21am UTC](https://discourse.slicer.org/t/save-directory-according-to-subject-hierarchy/20740/1 "2021-11-23T05:21:01Z")

</div>

Apologies if this is already possible, but it would be really helpful for me to save data nodes in a folder structure equivalent to the subject hierarchy (or maybe even arbitrary attributes) via GUI (I’m trying to use minimal code for a clinic-friendly handover document).  
I know we can create a subject hierarchy from a folder structure, how about the reverse?

Excellent software, btw 🙂

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [November 23, 2021, 3:22pm UTC](https://discourse.slicer.org/t/save-directory-according-to-subject-hierarchy/20740/2 "2021-11-23T15:22:29Z")

</div>

You can use [this code snippet](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#save-files-to-directory-structure-matching-subject-hierarchy-folders) to save nodes to the file system in the same directory structure as the subject hierarchy tree.

You can run this script on a keyboard combination (see how to [assign Ctrl+Shift+S keyboard shortcut here](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#export-labelmap-node-from-segmentation-node)) or you can override the default save dialog (or just update the paths automatically before showing the save dialog), add a toolbar button, custom module (especially if you already provide a module for some application-specific features), etc. All these just require a couple of lines of Python script.

---

<div class="post-metadata">

### Author: ![Kanga](https://avatars.discourse-cdn.com/v4/letter/k/6bbea6/32.png) [@Kanga](https://discourse.slicer.org/u/Kanga)
#### Post date: [November 24, 2021, 3:00am UTC](https://discourse.slicer.org/t/save-directory-according-to-subject-hierarchy/20740/3 "2021-11-24T03:00:39Z")

</div>

Thanks Andras for your very informative answer!
