Getting a list of all subdirectories in the current directory

后端 未结 29 2802
一个人的身影
一个人的身影 2020-11-22 08:02

Is there a way to return a list of all the subdirectories in the current directory in Python?

I know you can do this with files, but I need to get the list of direct

29条回答
  •  眼角桃花
    2020-11-22 08:41

    import os
    
    d = '.'
    [os.path.join(d, o) for o in os.listdir(d) 
                        if os.path.isdir(os.path.join(d,o))]
    

提交回复
热议问题