import os def f(path='.'): p=os.path.abspath(path) for v in [x for x in os.listdir(p) if os.path.isdir(x)]: cpth=os.path.join(p,v) #子目录的绝对路径 print(cpth) f(cpth) #递归,这样就能找出子母录的子目录的子目录的......
os.path.isdir() 函数需要绝对路径。如下修改即可。
for v in [x for x in os.listdir(p) if os.path.isdir(os.path.join(p,x))]:
Sign in to make a reply
落魄的毛哥