2016-02-12 90 views

回答

3

我覺得這可能是一個合適的解決方案:

# 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] 

所以基本上glob.iglob('*.log')只是一個數組(更準確地說它的結果是發電機) - 您可以通過的ctime排序並找到你想要的。

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