I have a folder with a bunch of files. Is there a way to select the file that is the most recently updated?
For example:
FTP_FOLDER = os.path.join(os.getcwd(), 'ftp_folder')
xml_files = [file for file in glob.glob(os.path.join(FTP_FOLDER, '*.xml'))]
Now, how to get the most recent xml_file?
Use os.path.getmtime
to get the file modification time:
import os
xml_files.sort(key=os.path.getmtime)
print xml_files[-1] # most recent file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With