generate_structure.py (632B)
1 import os 2 3 def save_structure_to_txt(target_dir, output_file): 4 with open(output_file, 'w', encoding='utf-8') as f: 5 for root, dirs, files in os.walk(target_dir): 6 level = root.replace(target_dir, '').count(os.sep) 7 indent = ' ' * level 8 f.write(f"{indent}{os.path.basename(root)}/\n") 9 for file in files: 10 f.write(f"{indent} {file}\n") 11 12 target = r'G:\bsc' 13 output = 'directory_structure.txt' 14 15 if os.path.exists(target): 16 save_structure_to_txt(target, output) 17 print(f"Structure saved to {output}") 18 else: 19 print(f"The path {target} does not exist.")