How to list only top level directories in Python?

前端 未结 18 1466
既然无缘
既然无缘 2020-12-04 07:51

I want to be able to list only the directories inside some folder. This means I don\'t want filenames listed, nor do I want additional sub-folders.

Let\'s see if an

18条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 08:49

    Using list comprehension,

    [a for a in os.listdir() if os.path.isdir(a)]
    

    I think It is the simplest way

提交回复
热议问题