Answer the question
In order to leave comments, you need to log in
How to find the right file?
In general, I have a database that is constantly automatically saved
while main_thread.is_alive():
sleep(7200)
with open(path, 'r') as f:
data = json.loads(f.read())
i = now.strftime("%d-%m-%Y-%H-%M")
with open(f"Saves/{i}.json", 'w') as f:
json.dump(data, f)
sleep(36000)
Answer the question
In order to leave comments, you need to log in
Isn't it easier when creating a save just to write the name of the save file in a specific file?
And in Python - just read the name of this file.
Depending on the traversal method, the traversal order is either undefined or specified as alphabetical by name.
Get a list of files and find the maximum by date in it.
https://docs.python.org/3/library/glob.html
https://stackoverflow.com/a/49871409/1762922
By the way, getting the date from the file name is also not difficult. strptime with the same format string will do most of the work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question