Instead, fullpath = os.path.join(path, file_pattern) is what you are looking for. I would recommend None Don't repeat yourselfĪs you can see, the two branches of your if else are very similar.īut joining paths like this is not very pythonic (and might cause problems on windows). Return os.path.split(max(list_of_files,key=os.path.getctime))įirst of all, I think that your variable names are quite good. List_of_files = glob.glob(''.format(path, file_pattern)) Inside my example/files directory are 3 files which were, for this example, created on the dates specified in the file name:Įxample/files/Įxample/files/Įxample/files/ import os.pathĭef get_latest_file(file_pattern,path=None): Taking a step back, it reads a bit janky and I was curious what steps or what resources I could look into to help me make this more friendly. I wrote a small function to help me find the latest file in a directory.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |