Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Open last saved CSV excel file via python

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading