python - pathlib.Path().glob() 和多个文件扩展名

标签 python path

我需要指定多个文件扩展名,如 pathlib.Path(temp_folder).glob('*.xls', '*.txt'):
我该怎么做?

https://docs.python.org/dev/library/pathlib.html#pathlib.Path.glob

最佳答案

如果你需要使用 pathlib.Path.glob()

from pathlib import Path
def get_files(extensions):
    all_files = []
    for ext in extensions:
        all_files.extend(Path('.').glob(ext))
    return all_files

files = get_files(('*.txt', '*.py', '*.cfg'))

关于python - pathlib.Path().glob() 和多个文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47655205/

相关文章:

java - 任何编程语言中的无理数表示?

python - ValueError ("No JSON object could be decoded") 使用 Python 2.6 和 utf-8

c++ - 带邻接表的 Dijkstra 算法

javascript - Mongoose ,解析嵌入式数组中的路径

bash - 安装 Node 时,我收到有关我的路径的提示

python - 类型错误 : ufunc subtract cannot use operands with types dtype ('<M8[ns]' ) and dtype ('float64' )

python - 将尾随空格添加到字符串列表

python - 给定 python 中的阈值,有效地删除彼此接近的数组

python - Pip 包路径 - windows

c# - 奇怪的 C# 路径问题