13
使用os.walk()递归遍历Python中的目录
我想从根目录导航到其中的所有其他目录并进行打印。 这是我的代码: #!/usr/bin/python import os import fnmatch for root, dir, files in os.walk("."): print root print "" for items in fnmatch.filter(files, "*"): print "..." + items print "" 这是我的O / P: . ...Python_Notes ...pypy.py ...pypy.py.save ...classdemo.py ....goutputstream-J9ZUXW ...latest.py ...pack.py ...classdemo.pyc ...Python_Notes~ ...module-demo.py ...filetype.py ./packagedemo ...classdemo.py ...__init__.pyc ...__init__.py ...classdemo.pyc 以上,.并且./packagedemo是目录。 但是,我需要通过以下方式打印O …