Python folder names in the directory

前端 未结 8 1157
傲寒
傲寒 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:39

    Use os.walk(path)

    import os
    
    path = 'C:\\'
    
    for root, directories, files in os.walk(path):
        for directory in directories:
            print os.path.join(root, directory)
    

提交回复
热议问题