import os
import sys
def export_directory_structure(export_file):
current_path = os.path.dirname(os.path.abspath(sys.argv[0]))
with open(export_file, 'w') as f:
f.write(f"Directory structure of {current_path}:\n")
f.write("\n")
_export_directory_structure(current_path, f, "")
def _export_directory_structure(path, export_file, prefix):
for item in os.listdir(path):
item_path = os.path.join(path, item)
if os.path.isdir(item_path):
export_file.write(f"{prefix}├─ {item}\n")
_export_directory_structure(item_path, export_file, prefix + "│ ")
else:
export_file.write(f"{prefix}├─ {item}\n")
# 测试
export_file = "目录结构.txt"
export_directory_structure(export_file)
print("目录结构导出成功!")
2.生成当前文件所在文件夹的目录结构
于 2023-11-01 12:33:08 首次发布