语法格式大致如下:
os.walk(top[, topdown=True[, one rror=None[, followlinks=False]]])
显示目录下所有文件
#conding=utf8 import os g = os.walk(r"e:\test") for path,dir_list,file_list in g: for file_name in file_list: print(os.path.join(path, file_name) )
显示所有子目录
#conding=utf8 import os g = os.walk("e:\test") for path,dir_list,file_list in g: for dir_name in dir_list: print(os.path.join(path, dir_name) )
原文链接:https://blog.csdn.net/mighty13/article/details/77995857