'PYTHON: How to delete a file in python after X amount of time, without constantly looking up the time
I was making a temporary file storage website, and all of the features of it are completed, but due to it being a "temporary" file storage website, it needs to delete files and make space for more files, but how'd one go about making a system that automatically deletes the file after let's say 1 hour of time or x minutes of time?
The file is stored in the database has the following properties:
HASHED_FILE_NAME- The hashed file name of the original file, the way it is stored in the directory, let's say the file is calledtest.mp4so what the program will do is that, it will run a hashing algorithm using python'ssecret.token_hex()method, which will ultimately convert it to a string likebf290fa34cf185ae.mp4.LINK_TO_THE_FILE- It is basically to add a extra layer of authentication so that no stranger stumbles upon the file on it's self, so it uses the same hashing function as before (secrets.token_hex()), but it is used to point back to theHASHED_FILE_NAMEso let's say if you go to the linkMY-WEBSITE.com/files/04f579669576dbe4the code04f579669576dbe4is going to point back tobf290fa34cf185ae.mp4which was originallytest.mp4.PRIMARY_KEY- This is pretty self explanatory, it just stores the primary key for the file.DATE_CREATED- This might be useful, it stores the date the file was uploaded on the server.
I just can't figure out how to use these properties of the file to delete the file after x amount of time, without constantly looking up the current time in the program.
Any solutions or suggestions are gladly accepted!
Thank you for your time!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
