如下所示:
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讀取目錄下最新的文件夾方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答