How To Use Python To Search For File By Name, Find The Latest Modified, Find Next File And Repeat Steps?
I have a folder that has many DWG files and an example of some files might be LINCOLN 09-17 #1-29H ASBUILT 10-26-2010.dwg LINCOLN 09-17 #1-29H FINAL 01-20-2011.dwg CAMPBELL 07-17 #
Solution 1:
You need to go searching for the suitable files, and remeber the newest of each one as you come accross it. Then report the latest.
In pseudo-code.
dates = dict() // key is filename, valueisdatefor subdir,dirs, files in os.walk(startdir):
if filename ends with "dwg":
if filename contains "FINAL":
date= getDate from filename
if dates contains filename
prev = dates(filename)
else
prev = zero date// a value so next line tests true always
if date> prev:
dates(filename) =date//else previous is younger, so skip//else draft oras built andskip//else filename not dwg andskipfor dates.values as v
print v
Post a Comment for "How To Use Python To Search For File By Name, Find The Latest Modified, Find Next File And Repeat Steps?"