# -*- coding: utf-8 -*- """ @author: Mr_zhang @software: PyCharm @file: export.py @time: 2022/6/29 14:57 """ import os import re exclude_file = "device|residence|custom_file|user|public|management|setting|models|00|pyc|__|urls|filters|views" pattern = re.compile(exclude_file) BASEDIR = os.path.dirname(__file__) def read_dir(path): _file_list = [] for dir_path, dirs, files in os.walk(path): for file in files: file_path = os.path.join(dir_path, file) if "\\" in file_path: file_path = file_path.replace("\\", "/") if not pattern.search(file_path): _file_list.append(file_path) for _dir in dirs: _file_list.extend(read_dir(os.path.join(dir_path, _dir))) return _file_list if __name__ == '__main__': file_list = read_dir(os.path.join(BASEDIR, "apps")) print(len(file_list)) for item in file_list: print(item) # with open("code.txt", "w+") as w: # for file in file_list: # with open(file, "r") as f: # w.writelines(f.readlines())