直接上代码:
#!/usr/bin/python
import os
for root, dirs, files in os.walk("Z:\script\python\/tmp\/"):
print("current dir is:" + root)
for name in dirs:
print("dirs:" + name)
for name in files:
print("file:" + name)
root是已经指定的根目录,dirs是根目录下的子目录,files是目录下的文件