【发布时间】:2022-01-11 16:07:39
【问题描述】:
我有一个与特定模式匹配的文件列表,我需要从中获取最新的和第二个最新的文件路径。
我可以使用以下代码获取最新文件
import glob
import os
list_of_files = glob.glob('/home/yash/proj_dir/reference_data/*/FeaturesV3.txt')
latest_file = max(list_of_files, key=os.path.getctime)
print(latest_file)
有没有办法从上述文件模式中获取第二个最新的文件?
【问题讨论】:
-
感谢您的指出。刚刚更新了。
-
这能回答你的问题吗? How to get the last element of a list
标签: python python-3.x list file