Get oldest folder

jyoung79 at kc.rr.com jyoung79 at kc.rr.com
Tue Apr 15 10:18:39 EDT 2008


I'd like to be able to get the path to the oldest folder in whatever directory I'm currently in.  Is there a simple way to go about this?  I'd like it to run on both OS X and Windows XP.  I found this example at "http://trac.v2v.cc/browser/python-v2v/v2v/v2v.py?rev=python-v2v%2C37", but was curious if there's a better way to do this?

def get_oldest_v2v_folder():
404	    '''
405	        returns the oldest folder in share_dir
406	        
407	        is this the right way to check for the oldest folder?
408	        could be better to read the info file and
409	        extract the date there.
410	    '''
411	    global share_dir
412	    oldest_timestamp=time.time()
413	    folders=listdir(share_dir)
414	    for folder in folders:
415	        if isdir(join(share_dir,folder)):
416	            if stat(join(share_dir,folder)).st_ctime < oldest_timestamp:
417	                oldest_timestamp=stat(join(share_dir,folder)).st_ctime
418	                oldest_folder=folder
419	    return join(share_dir,oldest_folder)

Thanks for looking at my question.

Jay



More information about the Python-list mailing list