Open last saved CSV excel file via python

Question:

I have an excel file to be downloaded in CSV format every day that it’s name changes daily. how can i open that file via python in Excel after being downloaded automatically?

I’ve tried the below solution but i have to mention the file name in full which I can’t do because it changes dynamically.

from subprocess import Popen
p = Popen('filename.csv', shell=True)
Asked By: Martina

||

Answers:

At the end of your code that downloads the file You can find latest file in your download folder as and open it

import glob
import os
from subprocess import Popen

list_of_files = glob.glob('/path_to_download_folder/*.csv') 
latest_csv_file = max(list_of_files, key=os.path.getctime)
print(latest_csv_file)
#then do what ever you want to do with it.
Answered By: Surjit Samra
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.