【发布时间】:2011-08-14 14:29:34
【问题描述】:
我想浏览当前文件夹及其所有子文件夹并获取所有带有 .htm|.html 扩展名的文件。我发现可以像这样找出一个对象是目录还是文件:
import os
dirList = os.listdir("./") # current directory
for dir in dirList:
if os.path.isdir(dir) == True:
# I don't know how to get into this dir and do the same thing here
else:
# I got file and i can regexp if it is .htm|html
最后,我希望将所有文件及其路径放在一个数组中。有这样的可能吗?
【问题讨论】:
-
但是这个答案更短更好。
标签: python subdirectory