这个链接使用的是自定义方法,但我只想知道在Python 2.6中是否有一种方法可以实现它?
没有内置函数只列出文件,但很容易定义几行:
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