Spaces:
Running
Running
Update app.py
#7
by
Duskfallcrew
- opened
Combined Output :
def increment_filename(filename):
"""
If a file exists, add a number to the filename to make it unique.
Example: if test.txt exists, return test(1).txt
"""
if not os.path.exists(filename):
return filename
directory = os.path.dirname(filename)
name, ext = os.path.splitext(os.path.basename(filename))
counter = 1
while True:
new_name = os.path.join(directory, f"{name}({counter}){ext}")
if not os.path.exists(new_name):
return new_name
counter += 1
Duskfallcrew
changed pull request status to
merged