Open files from multiple subdirectories

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!

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

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