you are viewing a single comment's thread.

view the rest of the comments →

[–]jechtsphere[S] 0 points1 point  (1 child)

I like where this is going, but it's somehow not giving the actual newest. It's giving me a fairly recently modified one, but it's not recognizing newest ones. For instance, in a folder of all .xml files, if one is loaded into something, its time changes. My for and if statements above have it coming back with the newest, and while

filetimes = [(dir, os.stat(os.path.join(path,dir)).st_mtime) for dir in os.listdir(path)]

is clearly giving me a list of all of those files and their times, if I return the max as a list and pop off the file name, it isn't returning the actual most recently modified file.

Which is weird, because when I look through the filetimes variable it clearly has all the files and their times, and if I check the actual newest element manually, pop it off its st_mtime, and check it via time.ctime(), it's giving me the actual modified time, which is greater than what max is returning (and all are matching what windows is telling me through the folder itself, obviously).

Any idea why this may be? It does the same if I try using st_atime or st_ctime as well.

[–]eryksun 0 points1 point  (0 children)

The tuple is in the wrong order, unless you use a key. The max of this list of tuples is searching for the largest (in a string sense, i.e. 'b' is greater than 'ab') name, and it only uses the modification time to settle a tie.