Skip to content

Instantly share code, notes, and snippets.

@terrycojones
Created January 30, 2013 11:19
Show Gist options
  • Save terrycojones/4672571 to your computer and use it in GitHub Desktop.
Save terrycojones/4672571 to your computer and use it in GitHub Desktop.
import os
def walk(root, startTimestamp, stopTimestamp):
"""
Walk the filesystem, descending from C{root}, yielding the paths of
files with modification dates more recent than C{startTimestamp} and at
most as recent as C{stopTimestamp}.
The aim is that our caller should be able to use the value of
C{stopTimestamp} from a call to us as the value of C{startTimestamp}
in a subsequent call, without missing any modified files.
@param root: The C{str} root of the filesystem to start at.
@param startTimestamp: The C{float} timestamp that files must be
newer than.
@param stopTimestamp: The C{float} timestamp that files cannot be
newer than.
@return: A generator yielding full file paths.
"""
for dirpath, dirnames, filenames in os.walk(root):
for name in filenames:
path = os.path.join(dirpath, name)
status = os.stat(path)
if startTimestamp < status.st_mtime <= stopTimestamp:
yield path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment