python_0">工具向,用python编写。
以下是代码:
python">import os
def generate_tree(path, level=0):
tree = ""
folder_name = os.path.basename(path)
if level == 0:
tree += f"{folder_name}\n"
else:
tree += f"{' ' * level}├── {folder_name}/\n"
items = os.listdir(path)
dirs = [item for item in items if os.path.isdir(os.path.join(path, item))]
files = [item for item in items if not os.path.isdir(os.path.join(path, item))]
for item in sorted(dirs) + sorted(files):
if os.path.isdir(os.path.join(path, item)):
tree += generate_tree(os.path.join(path, item), level+1)
else:
tree += f"{' ' * (level+1)}├── {item}\n"
return tree
folder_path = os.getcwd()
tree = generate_tree(folder_path)
with open("file_tree.md", "w", encoding="utf-8") as f:
f.write(tree)
效果展示:
转化为:
stablediffusion-infinity
├── .vscode/
├── settings.json
├── 3rd/
├── outpur_dir_structure.py
├── PyPatchMatch/
├── __pycache__/
├── patch_match.cpython-39.pyc
├── csrc/
├── inpaint.cpp
├── inpaint.h
├── masked_image.cpp
├── masked_image.h
├── nnf.cpp
├── nnf.h
├── pyinterface.cpp
├── pyinterface.h
├── examples/
├── images/
├── forest.bmp
├── forest_pruned.bmp
├── .gitignore
├── cpp_example.cpp
├── cpp_example_run.sh
├── py_example.py
├── py_example_global_mask.py
├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── libpatchmatch.dll
├── opencv_world460.dll
├── patch_match.py
├── travis.sh
├── __pycache__/
├── perlin2d.cpython-39.pyc
├── postprocess.cpython-39.pyc
├── utils.cpython-39.pyc
├── css/
├── w2ui.min.css
├── js/
├── fabric.min.js
├── keyboard.js
├── mode.js
├── outpaint.js
├── proceed.js
├── setup.js
├── toolbar.js
├── upload.js
├── w2ui.min.js
├── xss.js
├── models/
├── v1-inference.yaml
├── v1-inpainting-inference.yaml
├── .gitattributes
├── README.md
├── app.py
├── canvas.py
├── config.yaml
├── convert_checkpoint.py
├── file_tree.md
├── index.html
├── packages.txt
├── perlin2d.py
├── postprocess.py
├── process.py
├── requirements.txt
├── utils.py