I have a folder structure with some epubs and json files in the down-most folders (not counting the .ts folders). I'm exporting tags from the json files to tagspaces, by creating a .ts folder with some other json files. I've already processed part of the files and now I want to find the leaf folders that don't have a .ts folder in their path, to find the remaining files without having to process the others twice.
So for this example I only want to do something for the folder t5:
test
├── t1
│ ├── t2
│ │ └── t5
│ └── t3
│ └── .ts
└── .ts
└── t4
This is what I've tried:
def process_files_in_leaf_subdirectories(dir: str) -> None:
dirs = []
for root, subdirs, filenames in os.walk(dir):
if subdirs or '.ts' in root:
continue
dirs.append(root)
return dirs
def test_process_files_in_leaf_subdirectories():
os.makedirs('tmp/t1/t2/t5', exist_ok=True)
os.makedirs('tmp/t1/t3/.ts', exist_ok=True)
os.makedirs('tmp/.ts/t4', exist_ok=True)
assert get_files_in_leaf_subdirectories('tmp') == ['tmp/t1/t2/t5']
shutil.rmtree('tmp')