Second newest file

I think this can be a suitable solution:

# for the min + 1
sorted(glob.iglob('*.log'), key=os.path.getctime)[1]

# for the newest
sorted(glob.iglob('*.log'), key=os.path.getctime)[-1]

# for the second newest ( max - 1)
sorted(glob.iglob('*.log'), key=os.path.getctime)[-2]

So basically glob.iglob('*.log') is just an array (to be more precise it result is a generator) - you can sort it by ctime and find what you want.


sorted_list = sorted(glob.iglob('upload/*.log'), key=os.path.getctime)
sorted_list[-2]