Python源码导出到一个txt文件

复制代码
# -*- 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())
复制代码

 

posted @   一石数字欠我15w!!!  阅读(369)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
历史上的今天:
2021-06-29 项目部署
2018-06-29 一套小学生的试卷。。。
2018-06-29 python基础小练习
2018-06-29 Django-配置celery
点击右上角即可分享
微信分享提示