[Python] A safe, atomic file-copy operation

Discussão em 'Python' iniciado por Stack, Agosto 8, 2025.

  1. Stack

    Stack Membro Participativo

    I need to copy a file from one location to another, and I need to throw an exception (or at least somehow recognise) if the file already exists at the destination (no overwriting).

    I can check first with os.path.exists() but it's extremely important that the file cannot be created in the small amount of time between checking and copying.

    Is there a built-in way of doing this, or is there a way to define an action as atomic?

    Continue reading...

Compartilhe esta Página