Print out the whole directory tree

后端 未结 4 554
眼角桃花
眼角桃花 2021-01-03 11:05

The code I have now:

import os

Tree = {}
Tree = os.listdir(\'Dir\')
>>> print(Tree)
[\'New Folder\', \'Textfile1.txt\', \         


        
4条回答
  •  甜味超标
    2021-01-03 11:35

    Use os.walk:

    >>> import os
    >>> print(os.walk.__doc__)
    Directory tree generator.
    
        For each directory in the directory tree rooted at top (including top
        itself, but excluding '.' and '..'), yields a 3-tuple
        ...
    

提交回复
热议问题