Fork me on GitHub

Python之查找某目录中最新的文件

记录一下这个方法,感觉很有用!>.<

复制代码
 1 import os
 2 def find_newest_file(path_file):
 3     lists = os.listdir(path_file)
 4     lists.sort(key=lambda fn: os.path.getmtime(path_file +'\\'+fn))
 5     print(lists)
 6     file_newest = os.path.join(path_file,lists[-1])
 7     return file_newest
 8 if __name__ =='__main__':
 9     file_newest = find_newest_file(r'D:\pythoncode\login_test\report')
10     print(file_newest)
复制代码
posted @   linux超  阅读(1067)  评论(0编辑  收藏  举报
编辑推荐:
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· Linux系列:如何调试 malloc 的底层源码
阅读排行:
· C# 中比较实用的关键字,基础高频面试题!
· .NET 10 Preview 2 增强了 Blazor 和.NET MAUI
· 为什么AI教师难以实现
· 如何让低于1B参数的小型语言模型实现 100% 的准确率
· AI Agent爆火后,MCP协议为什么如此重要!
点击右上角即可分享
微信分享提示