1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import os ''' 递归遍历当前目录下面的所有文件. 可以设置过滤的文件. ''' path="." # 过滤的文件 entryNameFilter=["app - 副本.json","app.json","App.vue","main.js"] def scanDir(path=""): with os.scandir(path) as it: for entry in it: if not entry.name.startswith('.') and entry.name not in entryNameFilter and entry.is_file(): print(entry.path) #with open(entry.path,"r",encoding="utf-8") as rrs: # print(rrs.read()) elif entry.is_dir(): scanDir(entry.path) if __name__ == '__main__': scanDir(".") |