Jonathan Gavriel Jonathan Gavriel - 4 years ago 154
Python Question

Python Open File path that changes dynamically

I have a file that is updated throughout the day and the name of that file changes with a time signature of when the file was updated.

e.g.


\folder\todolist\grocerylist_2015-12-30-093000.csv


How can I open this file in python without manually updating the full file path?

Answer Source

You can use the glob module to handle this.

import glob
file_path = glob.glob('\\folder\\todolist\\grocerylist_*.csv')[0]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download