This is more or less reverse question to List directory tree structure in python? and this answer https://stackoverflow.com/a/51991554/7422721
Given that we have text art style directory tree (ASCII, but not limited to), generated as an output from tree
program or equivalent Python script:
a/
├── b/
│ └── c/
│ ├── file_1
│ └── file_2
└── d/
Each file name ends with one of the '/', '=', '*', '@', '|' or '>'
indicating file type, as with the ls -F
or tree -F
convention. So file name ending with /
would be directory, =
for socket etc. If there is no ending, we assume that it is regular file.
How can I read this back into native data structure, for example:
[
"a": [
"b": [
"c": [
"file_1", "file_2"
]
],
"d": []
]
]
Or to other object that could represent in memory filesystem?
Goal here would be to create readable unit tests for script that manipulates files on disk.