儿茶,株洲长途汽车站,律政男神解读网贷新规
本文实例讲述了Python实现遍历目录的方法。分享给大家供大家参考,具体如下:
# *-* coding=gb2312 *-* import os.path import shutil def traveltree(curPath,count): if not os.path.exists(curPath): return if os.path.isfile(curPath): fileName =os.path.basename(curPath) print '\t' *count+ '├─' + fileName elif os.path.isdir(curPath): print '\t' *count+ '├─' + curPath pathlist =os.listdir(curPath) for aa in pathlist: traveltree(curPath +"\\"+aa,count+1) if __name__=='__main__': traveltree("C:\\py",1)
运行效果图如下:
更多关于Python相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家Python程序设计有所帮助。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Python 实现将numpy中的nan和inf,nan替换成对应的均值
python爬虫把url链接编码成gbk2312格式过程解析
网友评论