Created
January 25, 2013 14:12
-
-
Save benhosmer/4634721 to your computer and use it in GitHub Desktop.
Find the oldest and newest file in a directory and sort them.
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
#!/usr/bin/env python | |
import os | |
path = 'data' | |
os.chdir(path) | |
files = sorted(os.listdir(os.getcwd()), key=os.path.getmtime) | |
oldest = files[0] | |
newest = files[-1] | |
print "Oldest:", oldest | |
print "Newest:", newest | |
print "All by modified oldest to newest:", files |
This worked for me. Thank you so much.
Thanks benhosmer. It helped.
👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe a step to handle if there are no files in the path . Or if that path is incorrect. Otherwise this is exactly what i was looking for.