Top.Mail.Ru
Ответы

Помогите с задачей по python

По дате
По рейтингу
Аватар пользователя
Искусственный Интеллект
3нед

Примерно так:

1234567891011121314151617181920212223242526272829303132333435
import json
import shutil
import os

def main():
    json_filename = input("Введите имя JSON файла с командами: ").strip()
    
    try:
        with open(json_filename, 'r', encoding='utf-8') as f:
            data = json.load(f)
    except Exception as e:
        print(f"Ошибка чтения файла: {e}")
        return

    command = data.get("command")
    args = data.get("arguments", {})

    if command == "move":
        source = args.get("source")
        destination = args.get("destination")
        if source and destination:
            try:
                shutil.move(source, destination)
                print(f"Файл перемещён из {source} в {destination}")
            except Exception as e:
                print(f"Ошибка при перемещении: {e}")
        else:
            print("Ошибка: отсутствуют поля source или destination")

    else:
        print(f"Неизвестная команда: {command}")

if __name__ == "__main__":
    main()