Thank you everyone. It worked. Here is the BETA 0.9 :)
import os, time, sys from stat import * def findfile(path): file_list = [] for f in os.listdir(path): filename = os.path.join(path, f) if not os.path.isfile(filename): print "*** Not a file:", repr(filename) continue create_date_secs = os.stat(filename)[ST_CTIME] create_date = time.strftime("%Y%m%d%H%M%S", time.localtime(create_date_secs)) file_list.append((create_date, filename)) file_list.sort() print file_list[-2] return file_list[-2] if __name__ == '__main__': path = r'\\rad-db02-ny\c$\backup\rad_oltp' create_date, prev_file = findfile(path) print "Previous back file is: ", prev_file, " ", create_date Now I am going to read this file and manupulate stuff with DB so I am going to work on ODBC connection using python.. interesting stuff. Thank you all, hj Hitesh wrote: > Hi, > > I have a small script here that goes to inside dir and sorts the file > by create date. I can return the create date but I don't know how to > find the name of that file... > I need file that is not latest but was created before the last file. > Any hints... I am newbiw python dude and still trying to figure out lot > of 'stuff'.. > > > import os, time, sys > from stat import * > > def walktree(path): > test1 = [] > for f in os.listdir(path): > filename = os.path.join(path, f) > create_date_sces = os.stat(filename)[ST_CTIME] > create_date = time.strftime("%Y%m%d%H%M%S", > time.localtime(create_date_sces)) > print create_date, " ....." , f > test1.append(create_date) > test1.sort() > print test1 > return test1[-2] > > > if __name__ == '__main__': > path = '\\\\srv12\\c$\\backup\\my_folder\\' > prev_file = walktree(path) > print "Previous back file is ", prev_file > > > Thank you, > hj -- http://mail.python.org/mailman/listinfo/python-list