List Directories and get the name of the Directory

前端 未结 4 971
再見小時候
再見小時候 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:25

    You seem to be using Python as if it were the shell. Whenever I've needed to do something like what you're doing, I've used os.walk()

    For example, as explained here: [x[0] for x in os.walk(directory)] should give you all of the subdirectories, recursively.

提交回复
热议问题