How to get recent files written to directory if 2 files are written program should detect 2 files using python -


i trying recent files witten directory. below code using.

 filelist = max(glob.iglob(path_to_midterm+"\\*.zip"), key=os.path.getctime) 

this code giving me recent file. if there multiple files written in directory still giving me 1 file. so, want if there multiple files written @ same time of files. how files?

i'd files, find out oldest , use within ten seconds of time:

filenames_and_times = [ (filename, os.path.getctime(filename))     filename in glob.iglob(path_to_midterm+"\\*.zip") ] time_of_last = max(filetime (_, filetime) in filenames_and_times) print [ filename     (filename, filetime) in filenames_and_times     if filetime > time_of_last - 10.0 ] 

alternatively sort list of filenames time , use last 4 entries or (depends on usecase if makes sense):

filenames_and_times.sort(key=lambda (f, t): t) print filenames_and_times[-4:] 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -