码迷,mamicode.com
首页 > 编程语言 > 详细

【python】获取目录下的最新文件夹/文件

时间:2017-12-13 23:55:40      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:return   ==   lists   file   时间   pytho   __name__   body   time   

直接上代码

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

 

【python】获取目录下的最新文件夹/文件

标签:return   ==   lists   file   时间   pytho   __name__   body   time   

原文地址:http://www.cnblogs.com/pipihaoke/p/8034395.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!