Python 遍历目录
代码:
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" + s root = "E:/DataBase/EyeVive3/070802/f" for i in os.listdir(root): if os.path.isfile(os.path.join(root,i)): print i