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
If all files being numbered isn't a problem, and you know beforehand the name of the file to be written, you could simply do:
import os counter = 0 filename = "file{}.pdf" while os.path.isfile(filename.format(counter)): counter += 1 filename = filename.format(counter)