Python 遍历目录

来源:互联网 发布:windows 桌面管理 编辑:程序博客网 时间:2024/05/22 21:13

代码:

1.递归使用遍历目录

import os    def scanfile(path):      filelist = os.listdir(path)      allfile = []      for filename in filelist:          filepath = os.path.join(path,filename)          if os.path.isdir(filepath):              scanfile(filepath)          print filepath  

2.使用listdir

import os//s = os.sep//root = "d:" + s + "ll" + sroot = "E:/DataBase/EyeVive3/070802/f" for i in os.listdir(root):    if os.path.isfile(os.path.join(root,i)):        print i


0 0
原创粉丝点击