How to get the late...
 
Share:
Notifications
Clear all

How to get the latest file in a folder?


myTechMint
(@mytechmint)
Member Moderator
Joined: 4 years ago
Posts: 52
Topic starter  

I need to get the latest file of a folder using python.


Quote
Topic Tags
myTechMint
(@mytechmint)
Member Moderator
Joined: 4 years ago
Posts: 52
Topic starter  

Use the following code. Make sure you change below '/path/to/folder/*' with your required path.

import glob
import os

list_of_files = glob.glob('/path/to/folder/*') # * means all if need specific format then *.csv
latest_file = max(list_of_files, key=os.path.getctime)
print(latest_file)

ReplyQuote