Represent directory tree as JSON

后端 未结 3 1006
甜味超标
甜味超标 2020-12-13 07:17

Is there any easy way to generate such a JSON? I found os.walk() and os.listdir(), so I may do recursive descending into directories and build a py

3条回答
  •  醉酒成梦
    2020-12-13 07:37

    On Linux, the command-line tool tree can be used, although it is not installed by default. The output is almost identical to that required by the OP, using the flag -J for JSON output (which can then be streamed to a file for example):

    tree -J folder
    

    On OSX, this tool can be installed via Homebrew.

提交回复
热议问题