jython - how to get the latest file in the folder -


I have written the code to be retrieved and the time it was created, I just want to get the latest filename. Please suggest how I can do Jethon. For the folder in glob.glob (file): > import glob for timing folder = 'c: / xml' in glob.glob. (Folder + '/ * .xml'): stats = os.stat (file) print file, time.ctime (statistics [8])

Thanks again for all your help

I have revised the code as suggested and I can not find the correct answer, please tell me what I am doing wrong.

import glob import time folder = 'c: / xml' for x in glob.glob (folder + "/ * .xml"): (mode, ino, dev, Time.ctime (mtime) for z in zip (nilink, uid), gid, size, atime, mtime, ctime) = os.stat (x) time1 = glob.glob (folder + "/ *. Xml"): (mode , IoO, Dev, Allicic, (time 1> time 2): new_file = x new_time = time1 else: new_file = z new_time = time2 print, time, time, time, time, time, time, minute, CTM) = Os.stat (z) time2 = time.ctime Use two variables to track the names and times of the new, new_file, new_time

later file, update both variables. When you are looped, the variable will have the name and time of the latest file.

I am not sure why your example code has two nested loops; If you have all the * in the given directory. Xml files, you only need one loop.

A pythonic solution might be something like this:

"" x

in
 maximum ()  solution, be sure to consider the case (max. (Os.stat (x) [8], x)  

Do the files in not * .xml are your directory.


Comments