首页 > 解决方案 > 如何打印以使用 python 开头的最新文件?

问题描述

是否可以使用打印最新文件startswith?示例:以“DOG”开头

import subprocess
import os
import glob

list_of_files = glob.iglob("C:\Users\Guest\Desktop\OJT\scanner\*")
latest_file = 
print latest_file

标签: pythonfileglob

解决方案


我不知道你的意思是什么startswith,但试试这个:

files = glob.iglob(r"C:\Users\Guest\Desktop\OJT\scanner\*")
latest_file = max(files, key=os.path.getctime)

推荐阅读