[Python] Create file but if name exists add number

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

  1. Stack

    Stack Membro Participativo

    Does Python have any built-in functionality to add a number to a filename if it already exists?

    My idea is that it would work the way certain OS's work - if a file is output to a directory where a file of that name already exists, it would append a number or increment it.

    I.e: if "file.pdf" exists it will create "file2.pdf", and next time "file3.pdf".

    Continue reading...

Compartilhe esta Página