您现在的位置是:python获取目录下的最新文件或文件夹

python获取目录下的最新文件或文件夹

分类: Python 日期:2019-08-15点击:2420
def new_report(test_report):
    lists = os.listdir(test_report)                                    #列出目录的下所有文件和文件夹保存到lists
    print(list)
    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
if __name__=="__main__":
    test_report="path"#目录地址
    new_report(test_report)
标签: Python

站长简介

    姓名:喻理
    微信:yuli0927
    邮箱:yuli0927@126.com
    不懂业务的运维工程师不是一个好程序员。

分类

最新文章

热门文章

全站标签