本文介绍了如何获取文件夹中的最新文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用 python 获取文件夹的最新文件.使用代码时:
I need to get the latest file of a folder using python. While using the code:
max(files, key = os.path.getctime)我收到以下错误:
FileNotFoundError: [WinError 2] 系统找不到指定的文件:'a'
推荐答案分配给 files 变量的内容不正确.使用以下代码.
Whatever is assigned to the files variable is incorrect. Use the following code.
import glob import os list_of_files = glob.glob('/path/to/folder/*') # * means all if need specific format then *.csv latest_file = max(list_of_files, key=os.path.getctime) print(latest_file)更多推荐
如何获取文件夹中的最新文件?
发布评论