# Open files from multiple subdirectories

**URL:** <https://discourse.slicer.org/t/open-files-from-multiple-subdirectories/3035>\
**Category:** Support\
**Created:** [June 1, 2018, 9:16am UTC](https://discourse.slicer.org/t/open-files-from-multiple-subdirectories/3035 "2018-06-01T09:16:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ladybug](https://avatars.discourse-cdn.com/v4/letter/l/46a35a/32.png) [@ladybug](https://discourse.slicer.org/u/ladybug)\
**Post date:** [June 1, 2018, 9:16am UTC](https://discourse.slicer.org/t/open-files-from-multiple-subdirectories/3035/1 "2018-06-01T09:16:32Z")

</div>

Hello,

I’m trying to open files with extension .nrrd from multiple subfolders. So far I only got to open one file at a time. This is the working version:  
dir\_path = qt.QFileDialog.getOpenFileName(self.parent, ‘Open file’, ‘D:\SlicerTest\THA’, “All Files (\*.nrrd)”)  
dir\_path = dir\_path.replace("\", “/”)

The other version that is not working (the files with my .nrrd extension are not even visible) looks as follows:  
dir\_path = qt.QFileDialog.getExistingDirectory(None, ‘Open folder’, ‘/home/’, qt.QFileDialog.ShowDirsOnly)  
Also, I would like to select the folders that I want to open, e.g. from 89 to 95.

I would appreciate any feedback.  
Best!

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [June 1, 2018, 1:47pm UTC](https://discourse.slicer.org/t/open-files-from-multiple-subdirectories/3035/2 "2018-06-01T13:47:52Z")

</div>

> [@ladybug](#):
>
> I’m trying to open files with extension .nrrd

Have a look at the utility functions to open files via python, starting here:

[https://github.com/Slicer/Slicer/blob/dc998411aff0cc92c137374a297de6a1c5c52a88/Base/Python/slicer/util.py#L320](https://github.com/Slicer/Slicer/blob/dc998411aff0cc92c137374a297de6a1c5c52a88/Base/Python/slicer/util.py#L320)

> [@ladybug](#):
>
> I would like to select the folders that I want to open, e.g. from 89 to 95.

You can use python’s directory iteration tool to get the file or directory names, and then test the filename to make your selection, see:

[https://github.com/Slicer/Slicer/blob/dc998411aff0cc92c137374a297de6a1c5c52a88/Base/Python/slicer/util.py#L1317-L1329](https://github.com/Slicer/Slicer/blob/dc998411aff0cc92c137374a297de6a1c5c52a88/Base/Python/slicer/util.py#L1317-L1329)
