文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>python遍历文件夹

python遍历文件夹

时间:2005-07-19  来源:jerryfleming

根据别人的算法用python实现

#!/usr/bin/python

from os.path import basename, isdir
from os import listdir

def traverse(path, depth=0):
 prefix =  depth* '| ' + '|_'
 if(isdir(path)):
  print prefix, basename(path)
  for item in listdir(path):
   traverse(path+'/'+item, depth+1)
 else:
  print prefix, basename(path)

if __name__ == '__main__':
 traverse('./')

相关阅读 更多 +
排行榜 更多 +
草艺大师

草艺大师

休闲益智 下载
易家学府

易家学府

学习教育 下载
欢乐球球吃吃

欢乐球球吃吃

休闲益智 下载