CPUtils
fsWatcher
get_directories_recursive(path)
Recursively list all directories under path, including path itself, if it's a directory.
The path itself is always yielded before its children are iterated, so you can pre-process a path (by watching it with inotify) before you get the directory listing.
Source code in cputils/fsWatcher.py
def get_directories_recursive(path) :
'''
Recursively list all directories under path, including path itself, if
it's a directory.
The path itself is always yielded before its children are iterated, so you
can pre-process a path (by watching it with inotify) before you get the
directory listing.
'''
if path.is_dir() :
yield path
for child in path.iterdir():
yield from get_directories_recursive(child)
elif path.is_file() :
yield path