如何获取文件夹中的最新文件?

编程入门 行业动态 更新时间:2024-10-23 16:17:27
本文介绍了如何获取文件夹中的最新文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要使用 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)

更多推荐

如何获取文件夹中的最新文件?

本文发布于:2023-10-30 19:28:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1543782.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   夹中   最新

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!