Python3遍历指定文件夹下所有文件及文件夹
程序员文章站
2022-03-25 22:21:21
采用os模块儿: ......
采用os模块儿:
import os def get_filelist(dir): for home, dirs, files in os.walk(dir): print("#######dir list#######") for dir in dirs: print(dir) print("#######dir list#######") print("#######file list#######") for filename in files: print(filename) fullname = os.path.join(home, filename) print(fullname) print("#######file list#######") if __name__ == "__main__": get_filelist('c:\\python3\\scripts')