python遍历目录主要使用os模块的walk方法,可以获取到目录名,文件名
简单记录下,以后能够用上
#!/usr/bin/python3 #coding:utf-8 import os import zipfile def list_dir(work_dir): for parent, dirnames, filenames in os.walk(work_dir, followlinks=True): for filename in filenames: file_path = os.path.join(parent, filename) print("文件名%s,文件路径是%s,所在目录是%s" % (filename, file_path, parent)) if __name__ == "__main__": list_dir("D:\\blog")