[Python] I am trying to replace a file using import os but it keeps saying "directory not...

Discussão em 'Python' iniciado por Stack, Junho 24, 2025.

  1. Stack

    Stack Membro Participativo

    import os

    source = "/storage/emulated/0/converted.py"
    destination = "/storage/emulated/0/DCIM"
    try:
    if os.path.exists(destination):
    print("file already there")
    if os.replace(source, destination):
    print(source + " was moved")
    except FileNotFoundError:
    print(source + " file was not found")


    After trying to replace a file by another I get an error "directory not empty".

    Should the destination be empty before replacing? And I sometimes get an error saying "not a directory" and I was just wondering if I can only transfer files from directory to directory alone? Or can transfer from both (directory and folder)?

    Continue reading...

Compartilhe esta Página