import os import string import shutil Шаблон содержимого файлов FILECONTENT =…
- User
import os import string import shutil
Шаблон содержимого файлов
FILE_CONTENT = """#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() {
codereturn 0;} """
def get_folder_name(): while True: folder_name = input("Введите имя новой папки: ").strip() if not folder_name: print("Имя папки не может быть пустым. Пожалуйста, попробуйте снова.") else: return folder_name
def get_last_letter(): while True: last_char = input("Введите последнюю букву для создания файлов (A-Z): ").strip().upper() if len(last_char) != 1 or last_char not in string.ascii_uppercase: print("Пожалуйста, введите одну букву от A до Z.") else: return last_char
def create_folder(folder_path): if not os.path.exists(folder_path): try: os.makedirs(folder_path) print(f"Папка '{folder_path}' успешно создана.") except Exception as e: print(f"Не удалось создать папку '{folder_path}'. Ошибка: {e}") return False else: print(f"Папка '{folder_path}' уже существует. Будет произведено копирование содержимого.") return True
def copy_template(template_path, destination_path): if not os.path.exists(template_path): print(f"Папка 'template' не найдена в '{os.getcwd()}'. Убедитесь, что она существует.") return False try: # Копируем содержимое папки template в destination_path for item in os.listdir(template_path): s = os.path.join(template_path, item) d = os.path.join(destination_path, item) if os.path.isdir(s): shutil.copytree(s, d, dirs_exist_ok=True) else: shutil.copy2(s, d) print(f"Содержимое папки 'template' успешно скопировано в '{destination_path}'.") except Exception as e: print(f"Не удалось скопировать содержимое из 'template'. Ошибка: {e}") return False return True
def create_cpp_files(destination_path, last_char): # Определяем диапазон букв от 'A' до last_char letters = list(string.ascii_uppercase) try: end_index = letters.index(last_char) + 1 # +1 для включения последней буквы except ValueError: print(f"Буква {last_char} не найдена в английском алфавите.") return
codeselected_letters = letters[:end_index] for letter in selected_letters: filename = f"{letter}.cpp" file_path = os.path.join(destination_path, filename) if os.path.exists(file_path): print(f"Файл '{filename}' уже существует в '{destination_path}'. Пропускаю создание.") continue try: with open(file_path, 'w') as file: file.write(FILE_CONTENT) print(f"Создан файл: {file_path}") except Exception as e: print(f"Не удалось создать файл '{filename}'. Ошибка: {e}") - Assistant