遍历文件夹下的所有文件
1 rootdir = d:\data\ # 指明被遍历的文件夹 2 print rootdir 3 for parent, dirnames, filenames in os.walk(rootdir): # 三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 4 for dirname in dirnames: # 输出文件夹信息 5 print 111 6 print "parent is:" + parent 7 print "dirname is" + dirname 8 for filename in filenames: # 输出文件信息 9 print "parent is:" + parent 10 print "filename is:" + filename 11 print "the full name of the file is:" + os.path.join(parent, filename) # 输出文件路径信息
kingrain送给读者的话:Everthing isn't getting along well,your efforts paid off!