Find Files in a Folder Between 2 Dates
python.list at tim.thechases.com
Fri Dec 5 00:42:19 CET 2008
> Is there a way to find all the files in a folder, between 2 dates?
> For example:
> Firstdate = 200801010000
> Seconddate = 200801020000
> Find all the files in C:\Folder that are between Firstdate and
This should do it:
firstdate = "200801010000"
seconddate = "200801020000"
return time.mktime(time.strptime(s, "%Y%m%d%H%M"))
start = get_timestamp(firstdate)
end = get_timestamp(seconddate)
location = '/path/to/wherever/'
files = [fname
for fname in os.listdir(location)
if start <=
The magic is the the os.stat(f).st_mtime to determine when the
associated timestamp, the os.listdir() to get the available files
in a directory, and the list-comprehension to filter to only the
ones you want.
More information about the Python-list