Сделай короче туглы выбор какие файлы сканировать типо cs py и html import os import…
- User
Сделай короче туглы выбор какие файлы сканировать типо cs py и html import os import tkinter as tk from tkinter import filedialog
def scan_directory(start_path, indentation_level=0, file=None, shallow_scan=False, include_cs_content=False): """ Рекурсивно сканирует директорию и записывает структуру каталогов и файлов в файл. Если include_cs_content=True, также записывает содержимое .cs файлов. """ try: for item in os.listdir(start_path): item_path = os.path.join(start_path, item) indent = ' ' * indentation_level * 4 if os.path.isdir(item_path): print(f'{indent}📁 {item}', file=file) if not shallow_scan: scan_directory(item_path, indentation_level + 1, file=file, shallow_scan=shallow_scan, include_cs_content=include_cs_content) elif item.endswith('.cs'): print(f'{indent}📄 {item}', file=file) if include_cs_content: print(f'\n\n{"=" * 20}\n{item_path}\n{"=" * 20}\n', file=file) try: with open(item_path, 'r', encoding='utf-8') as cs_file: cs_content = cs_file.read() print(cs_content, file=file) except Exception as e: print(f"Ошибка при чтении файла {item_path}: {e}", file=file) else: print(f'{indent}📄 {item}', file=file) except Exception as e: print(f"Ошибка при сканировании {start_path}: {e}", file=file)
def start_scan(shallow_scan): """ Вызывает диалог выбора директории и запускает сканирование с учетом выбранных параметров. """ path = filedialog.askdirectory() if path: with open('cs_structure.txt', 'w', encoding='utf-8') as structure_file: scan_directory(path, file=structure_file, shallow_scan=shallow_scan, include_cs_content=False) print("Иерархия каталогов и файлов сохранена в файле 'cs_structure.txt'.")
codewith open('cs_scripts.cs', 'w', encoding='utf-8') as scripts_file: scan_directory(path, file=scripts_file, shallow_scan=shallow_scan, include_cs_content=True) print("Структура папок и файлов, а также содержимое .cs файлов, сохранены в файле 'cs_scripts.cs'.") else: print("Папка не выбрана.")def create_interface(): """ Создает графический интерфейс пользователя с помощью tkinter. """ root = tk.Tk() root.title("Сканирование структуры папок")
code# Тумблер для выбора глубины сканирования shallow_scan_var = tk.BooleanVar(value=False) shallow_scan_toggle = tk.Checkbutton(root, text="Сканировать только верхние папки", variable=shallow_scan_var) shallow_scan_toggle.pack(pady=10) # Кнопка для выбора папки и начала сканирования scan_button = tk.Button(root, text="Выбрать папку и начать сканирование", command=lambda: start_scan(shallow_scan_var.get())) scan_button.pack(pady=10) root.mainloop() - Assistant