如果深度是固定的,
glob则是一个好主意:
import glob,os.pathfilesDepth3 = glob.glob('*/*/*')dirsDepth3 = filter(lambda f: os.path.isdir(f), filesDepth3)否则,它应该不会太难使用
os.walk:
import os,stringpath = '.'path = os.path.normpath(path)res = []for root,dirs,files in os.walk(path, topdown=True): depth = root[len(path) + len(os.path.sep):].count(os.path.sep) if depth == 2: # We're currently two directories in, so all subdirs have depth 3 res += [os.path.join(root, d) for d in dirs] dirs[:] = [] # Don't recurse any deeperprint(res)



