Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用OS库在python上迭代抛出文件列表_Python_Loops_Operating System - Fatal编程技术网

使用OS库在python上迭代抛出文件列表

使用OS库在python上迭代抛出文件列表,python,loops,operating-system,Python,Loops,Operating System,我需要在包含.doc documments的文件夹中使用特定格式名称迭代抛出文件,因此我需要名称中的一些键值,但问题是我不能像在字符串中那样迭代抛出它们。我使用的是:os.path.splitext(ruta),但它不返回任何值os library has walk()函数 import os dir = "sample_path" for root, dirnames, filenames in os.walk(dir): for filename in

我需要在包含.doc documments的文件夹中使用特定格式名称迭代抛出文件,因此我需要名称中的一些键值,但问题是我不能像在字符串中那样迭代抛出它们。我使用的是:
os.path.splitext(ruta)
,但它不返回任何值

os library has walk()函数

import os

dir = "sample_path"
for root, dirnames, filenames in os.walk(dir):
    
    for filename in filenames:
        # filename is a string.
        # perform your format matching.
        if "some_key_str" in filename and filename.endswith(".doc"):    # example
            pass