Exclude directories having no h5ad files

This commit is contained in:
Andreas Eisenbarth
2022-10-12 17:31:22 +02:00
parent 0e92b73347
commit 6607b15085
2 changed files with 5 additions and 1 deletions
@@ -63,7 +63,7 @@ class FileItemSource(ItemSource):
return item_tree
def scan_directory(self, subpath="") -> dict:
def scan_directory(self, subpath: str = "") -> ItemTree:
base_path = os.path.join(self.base_path, subpath)
if not os.path.exists(base_path):
@@ -100,6 +100,9 @@ class FileItemSource(ItemSource):
branches = [
self.scan_directory(os.path.join(subpath, subdir)) for subdir in subdirs
]
# Exclude branches without files as leaves. Since traversal is applied pre-order,
# branch.branches has already been processed and we don't need to check deeper nesting.
branches = [branch for branch in branches if branch.items or branch.branches]
return ItemTree(subpath, items, branches)