有没有办法获取Python中目录中的所有目录而不是文件?

Joa*_*nge 1 python directory

这个链接使用的是自定义方法,但我只想知道在Python 2.6中是否有一种方法可以实现它?

dF.*_*dF. 5

没有内置函数只列出文件,但很容易定义几行:

def listfiles(directory):
    return [f for f in os.listdir(directory) 
              if os.path.isdir(os.path.join(directory, f))]
Run Code Online (Sandbox Code Playgroud)

编辑:修复,谢谢Stephan202