m-teng/file_io.py

25 lines
482 B
Python
Raw Normal View History

2023-04-06 22:55:24 +02:00
from os import listdir, path
def get_next_filename(basename, directory=".", digits=3):
files = listdir(directory)
files.sort()
files.reverse()
lowest_number = 0
for file in files:
if not path.isfile(file): continue
if not file.startswith(basename): continue
try:
number = int(file.split('.')[0].strip(basename))
if number < lowest_number: continue
except ValueError:
continue