python3 遍历文件
程序很简单,parent,dirnames,filenames分别表明当前目录下的文件夹数及文件数,然后通过os.wolk向深入遍历。
import os
import os.path
# this folder is custom
rootdir="G:\Download"
for parent,dirnames,filenames in os.walk(rootdir):
#case 1:
for dirname in dirnames:
print("parent folder is:" + parent)
print("dirname is:" + dirname)
#case 2
for filename in filenames:
print("parent folder is:" + parent)
print("filename with full path:"+ os.path.join(parent,filename))