python读取目录下最新的文件夹方法
如下所示:
defnew_report(test_report): lists=os.listdir(test_report)#列出目录的下所有文件和文件夹保存到lists lists.sort(key=lambdafn:os.path.getmtime(test_report+"/"+fn))#按时间排序 file_new=os.path.join(test_report,lists[-1])#获取最新的文件保存到file_new print(file_new) returnfile_new
以上这篇python读取目录下最新的文件夹方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。