This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type DeepKeys<M> = { | |
[J in keyof M as `${J & string}${ | |
M[J] extends Record<string, any> ? | |
M[J] extends {constructor: M[J]} ? '' : | |
M[J] extends Array<any> ? '' : | |
`.${keyof DeepKeys<M[J]> & string}` : '' | |
}`]: | |
M[J] extends Record<string, any> ? M : M[J] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def dirtree(path): | |
steps = list(os.walk(path)) | |
def _tree(): | |
_, child_dirs, files = steps.pop(0) | |
obj = { child: _tree() for child in child_dirs } | |
obj['__files__'] = files | |
return obj | |
return _tree() |