I am writing a small script. The script creates .txt
files. I do not want to replace existing files. So what I want python to do is to check if the file already exists. If it does not it can proceed. If the file does exists I would like python to increment the name and than check again if the file already exists. If the file does not already exist python may create it.
EXAMPLE:
current dir has these files in it:
file_001.txt
file_002.txt
I want python to see that the two files exists and make the next file:
file_003.txt
creating files can be done like this:
f = open("file_001.txt", "w")
f.write('something')
f.close()
checking if a file exists:
import os.path
os.path.isfile(fname)