python - 读取文件名并直接写入列表

标签 python filenames

是否可以让 Python 查找文件夹并将所有文件名(具有特定扩展名)放入列表中?

例如:

[filename1.txt, filename2.txt,...]

最佳答案

您可以使用 glob 模块轻松完成此操作:

import glob
filenames = glob.glob('<some_path>/*.<extension>')

关于python - 读取文件名并直接写入列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12398311/

相关文章:

python - 检查范围内的字段

python - 如何在 python select() 中增加文件描述符的范围

Powershell:当文件名包含字符 [ ] 时,移动项目不起作用

Python - 压缩文件时出错, 'L' 格式要求 0 <= 数字 <= 4294967295

python - python中循环文件名

Python pocketsphinx RequestError : missing PocketSphinx module: ensure that PocketSphinx is set up correctly

Python oggenc 脚本

python - 两个节点之间所有路径的非常快速的算法

java - 来自 URL 的文件名不包含文件名后缀

linux - 从ftp获取同名文件