Python folder names in the directory

前端 未结 8 1205
傲寒
傲寒 2020-12-23 23:15

how can i get the folder names existing in a directory using Python ?

I want to save all the subfolders into a list to work with the names after that but i dont know

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 23:32

    For python 3 I'm using this script

    import os
    
    root='./'
    dirlist = [ item for item in os.listdir(root) if os.path.isdir(os.path.join(root, item)) ]
    for dir in dirlist:
            print(dir)
    

提交回复
热议问题