From 1d16a221f0dabe9e280945dcb6f46e4253f2cf98 Mon Sep 17 00:00:00 2001 From: VadimL Date: Thu, 8 Oct 2026 17:09:41 +0300 Subject: [PATCH] Some simle scripts --- python-sort-files-to-folders/main.py | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 python-sort-files-to-folders/main.py diff --git a/python-sort-files-to-folders/main.py b/python-sort-files-to-folders/main.py new file mode 100644 index 0000000..3ea7713 --- /dev/null +++ b/python-sort-files-to-folders/main.py @@ -0,0 +1,37 @@ +from pathlib import Path +import shutil +import sys + + +def organize_folder(folder: str): + path = Path(folder) + + if not path.is_dir(): + print(f"Ошибка: папка не существует: {path}") + return + + for file in path.iterdir(): + # Только обычные файлы, не папки + if not file.is_file(): + continue + + # Имя файла без последнего расширения + folder_name = file.stem + target_dir = path / folder_name + + # Создаём папку + target_dir.mkdir(exist_ok=True) + + # Перемещаем файл + target_file = target_dir / file.name + shutil.move(str(file), str(target_file)) + + print(f"{file.name} -> {folder_name}/") + + +if __name__ == "__main__": + if len(sys.argv) != 2: + print(f"Использование: {sys.argv[0]} <папка>") + sys.exit(1) + + organize_folder(sys.argv[1])