List Directories and get the name of the Directory

前端 未结 4 967
再見小時候
再見小時候 2020-12-29 00:57

I am trying to get the code to list all the directories in a folder, change directory into that folder and get the name of the current folder. The code I have so far is belo

4条回答
  •  死守一世寂寞
    2020-12-29 01:21

    import os
    for root, dirs, files in os.walk(top, topdown=False):
        for name in dirs:
            print os.path.join(root, name)
    

    Walk is a good built-in for what you are doing

提交回复
热议问题