What is the Python way to walk a directory tree?

后端 未结 11 1656
走了就别回头了
走了就别回头了 2020-12-06 09:52

I feel that assigning files, and folders and doing the += [item] part is a bit hackish. Any suggestions? I\'m using Python 3.2

from os import *
from os.pat         


        
11条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 10:05

    Take a look at the os.walk function which returns the path along with the directories and files it contains. That should considerably shorten your solution.

提交回复
热议问题