【发布时间】:2013-08-17 04:31:59
【问题描述】:
我正在尝试使用 fnmatch 来匹配 Python 中的目录。但不是只返回与模式匹配的目录,而是返回所有目录或不返回。
例如: F:\Downloads 有子目录 \The Portland Show、\The LA Show 等
我试图仅在 \The Portland Show 目录中查找文件,但它也返回 The LAS show 等。
代码如下:
for root, subs, files in os.walk("."):
for filename in fnmatch.filter(subs, "The Portland*"):
print root, subs, files
我不只是获取子目录“The Portland Show”,而是获取目录中的所有内容。我做错了什么?
【问题讨论】: