python 文件遍历
时间:2011-04-01 来源:Mingxx
1.
import os,sys
r = raw_input(“type a directory name”)
for root, dirs, files in os.walk(r):
for f in files:
print root, os.sep, f;
2.
import os,sys
def walkdir(dirname):
try:
ls = os.listdir(dirname)
except:
print ‘access deny’
else:
for l in ls:
temp = os.path.join(dirname,l)
if(os.path.isdir(temp):
walkdir(temp)
else
print temp;
if __name__ == “__main__”:
r = raw_input(“type a directory name:”)
walkdir(r)
相关阅读 更多 +