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)
@@ -116,6 +116,7 @@ class S3ItemSource(ItemSource):
branches = None
if len(subdir_keys) > 0:
branches = [self.scan_directory(key) for key in subdir_keys]
branches = [branch for branch in branches if branch.items or branch.branches]
return ItemTree(directory_key, items, branches)