Last active
August 29, 2015 14:14
-
-
Save PSJoshi/11643fb4231d943a2898 to your computer and use it in GitHub Desktop.
Find latest modified files in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Latest_files(options, roots): | |
"""" A generator to enumerate the contents of directories recursively. """ | |
for root in roots: | |
for dirpath, dirnames, filenames in os.walk(root): | |
name = os.path.split(dirpath)[1] | |
if any(fnmatch.fnmatch(name, w) for w in options.exc_dirs): | |
del dirnames[:] # Don't recurse here | |
continue | |
for fn in filenames: | |
if any(fnmatch.fnmatch(fn, w) for w in options.exc_files): | |
continue | |
path = os.path.join(dirpath, fn) | |
stat = os.lstat(path) | |
mtime = max(stat.st_mtime, stat.st_ctime) | |
yield mtime, stat.st_size, path | |
I do not remember the source. I will update as soon as I spot it again. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment