import osdef export_directory_structure(folder_path, output_file):with open(output_file, 'w', encoding='utf-8') as file:for root, dirs, files in os.walk(folder_path):level = root.replace(folder_path, '').count(os.sep)indent = ' ' * 4 * levelfile.write(f'{indent}{os.path.basename(root)}/\n')sub_indent = ' ' * 4 * (level + 1)for f in files:file.write(f'{sub_indent}{f}\n')
folder_path = '/path/to/your/folder'
output_file = 'directory_structure.txt'
export_directory_structure(folder_path, output_file)
print(f"目录结构已导出到 {output_file}")