Skip to main content
 首页 » 编程设计

python之使用 Python os.walk 识别文件列表

2025年05月04日11mate10pro

<分区>

Possible Duplicate:
In Python, fastest way to build a list of files in a directory with a certain extension

我目前正在使用 os.walk 递归扫描一个识别 .MOV 文件的目录

def fileList(): 
    matches = [] 
    for root, dirnames, filenames in os.walk(source): 
        for filename in fnmatch.filter(filenames, '*.mov'): 
            matches.append(os.path.join(root, filename)) 
    return matches 

我如何扩展它以识别多个文件,例如 .mov、.MOV、.avi、.mpg?

谢谢。