使用OS库在python上迭代抛出文件列表
我需要在包含.doc documments的文件夹中使用特定格式名称迭代抛出文件,因此我需要名称中的一些键值,但问题是我不能像在字符串中那样迭代抛出它们。我使用的是:使用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
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