如题,glob只能无法进入子文件夹
import os
for i in os.walk('e:'+os.sep+'case'):
print (i[1])
只能返回e:\case下面的文件夹名称
怎么处理啊
第1个回答 2013-12-17
import os
for root,dirs,files in os.walk('e:\\case'):
for filespath in files:
print(os.path.join(root,filespath))追问
path=r'e:\case'
fns=[os.path.join(root,fn) for root,dirs,files in os.walk(path) for fn in files]
for f in fns:
print(f)
print(len(fns))本回答被提问者和网友采纳
for root,dirs,files in os.walk('e:\\case'):
for filespath in files:
print(os.path.join(root,filespath))追问
能不能同时获得所遍历到的文件数量啊,不要包含文件夹
追答import ospath=r'e:\case'
fns=[os.path.join(root,fn) for root,dirs,files in os.walk(path) for fn in files]
for f in fns:
print(f)
print(len(fns))本回答被提问者和网友采纳
第2个回答 2015-10-06
import os
dir="e:\\"
for root,dirs,files in os.walk(dir):
for file in files:
print os.path.join(root,file)
dir="e:\\"
for root,dirs,files in os.walk(dir):
for file in files:
print os.path.join(root,file)