Get oldest folder

jyoung79 at jyoung79 at
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 "", 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
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.


More information about the Python-list mailing list