python - Retrieve files with date between date1 and date2 -


problem: retrieve files particular "path" satisfy below criteria: should file date falls in between 'startdate' , 'enddate'

example: fetch(path,startdate,enddate): path-> path of directory startdate-> date listed in ls (jun 27) enddate-> date listed in ls

and also, not able store o/p of 'ls -lrt' check particular pattern. can me !!!

this function might you:

from datetime import datetime os import path glob import glob time import time current_time  def get_files(pattern, start=0, end=none):     """     returns list of files in pattern files creation date between start , end     pattern = pattern retrieve files using glob     start = start date in seconds since epoch (default: 0)     end = end date in seconds since epoch (default: now)     """     start = datetime.fromtimestamp(start)     end = datetime.fromtimestamp(current_time() if end none else end)     result = []     file_path in glob(pattern):         if start <= datetime.fromtimestamp(path.getctime(file_path)) <= end:             result.append(file_path)     return result 

example:

>>> get_files('c:/python27/*') ['c:/python27\\dlls', 'c:/python27\\doc', 'c:/python27\\include', 'c:/python27\\lib', 'c:/python27\\libs', 'c:/python27\\license.txt', 'c:/python27\\news.txt', 'c:/python27\\python.exe', 'c:/python27\\pythonw.exe', 'c:/python27\\readme.txt', 'c:/python27\\tcl', 'c:/python27\\tools'] 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -