libb.get_directory_structure
- get_directory_structure(rootdir)[source]
Create a nested dictionary representing the folder structure.
- Parameters:
rootdir (str) – Root directory to traverse.
- Returns:
Nested dictionary of the directory structure.
- Return type:
Example:
>>> import tempfile, os >>> tmpdir = tempfile.mkdtemp() >>> os.makedirs(os.path.join(tmpdir, 'sub')) >>> Path(os.path.join(tmpdir, 'file.txt')).touch() >>> result = get_directory_structure(tmpdir) >>> 'file.txt' in result[os.path.basename(tmpdir)] True