Last active
August 29, 2015 14:02
-
-
Save wynnzen/b874e2c0c5b6f6b924ab to your computer and use it in GitHub Desktop.
遍历文件夹中的文件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import os.path | |
rootdir = "d:\data" # 指明被遍历的文件夹 | |
for parent,dirnames,filenames in os.walk(rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 | |
for dirname in dirnames: #输出文件夹信息 | |
print "parent is:" + parent | |
print "dirname is" + dirname | |
for filename in filenames: #输出文件信息 | |
print "parent is": + parent | |
print "filename is:" + filename | |
print "the full name of the file is:" + os.path.join(parent,filename) #输出文件路径信息 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment