python读取目录下最新的文件夹方法

时间:2022-11-28 18:56:39

如下所示:

?
1
2
3
4
5
6
def new_report(test_report):
 lists = os.listdir(test_report)         # 列出目录的下所有文件和文件夹保存到lists
 lists.sort(key=lambda fn: os.path.getmtime(test_report + "/" + fn)) # 按时间排序
 file_new = os.path.join(test_report, lists[-1])      # 获取最新的文件保存到file_new
 print(file_new)
 return file_new

以上这篇python读取目录下最新的文件夹方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/weixin_39012047/article/details/82498570