Python folder names in the directory

前端 未结 8 1155
傲寒
傲寒 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条回答
  •  -上瘾入骨i
    2020-12-23 23:28

    You should import os first.

    import os
    files=[]
    files = [f for f in sorted(os.listdir(FileDirectoryPath))]
    

    This would give you list with all files in the FileDirectoryPath sorted.

提交回复
热议问题