I need to be able to rename a file, continually increasing the number at the end of the file, without deleting a previous version of it. The original thought process was
file_path1 = "path/to/file/OLDqueues.sqlite"
try:
os.remove(file_path1)
except OSError as e:
print("Error: %s : %s" % (file_path1, e.strerror))
try:
os.rename(r'path\to\file\queues.sqlite', r'path\to\file\OLDqueues.sqlite')
except OSError as e:
print("Error: %s : %s" % (file_path1, e.strerror))
However, I've been told that we cannot delete the OLDqueues file in this process. What would be the best way to rename the file to OLDqueues, but if OLDqueues already exists- it will auto-rename to OLDqueues(1), then OLDqueues(2), etc?
For reference, I am using Python 3.7, and this will be applied to two files in different locations, but must not affect any other files in the directory.