Last active
January 30, 2018 14:41
-
-
Save lene/04768a4a70d8123b6b0eaf9350345382 to your computer and use it in GitHub Desktop.
Emulating UNIX command find(1) 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 find_files(base_path, condition): | |
return [ | |
os.path.join(root, file) | |
for root, _, files in os.walk(base_path) | |
for file in files | |
if os.path.exists(os.path.join(root, file)) # probably redundant, just making sure | |
if condition(os.path.join(root, file)) | |
] | |
# e.g. find -f -ctime -N | |
find_files(base_path, lambda file: time() - os.path.getctime(file) < 24*60*60*N) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment