ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

关于拷贝QQ、微信、企业微信等软件聊天过程中保存的文件

2022-07-22 18:39:23  阅读:181  来源: 互联网

标签:QQ uuid temp 微信 dst file path 拷贝 os


为什么

关于拷贝QQ、微信、企业微信等软件聊天过程中保存的文件,下午的时候整理资料,发现了去年的文件,直接开搞,把数据给整理处理

逻辑

递归遍历文件夹中的文件,碰到符合条件的后缀文件进行拷贝,如果有重命名的进行添加一个uuid

常见文件格式

需要添加什么可以可以自行进行添加

代码

# coding=utf-8
# @autor 爱喝水的木子
# @Time : 2022/7/22
# @FileName : 资源汇总.py
import os
import shutil
import uuid

# 常见文件格式
file_suffix = ['txt', 'wav', 'mp3', 'mp4', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'zip', 'rar', '7z', 'gz',
               'json', 'xml', 'html', 'htm', 'css', 'js', 'java', 'c', 'cpp', 'h', 'hpp', 'py', 'java', 'c', 'cpp', 'h',
               ]


# 命名重复的话添加uuid
def rename_file(path):
    if os.path.exists(path):
        uuid_str = str(uuid.uuid1().hex)
        path = path.replace(os.path.splitext(path)[1], "_{}".format(uuid_str) + os.path.splitext(path)[1])
        return path
    else:
        return path


def yid_data_to_move(src):
    dst = os.path.join(base_dir, os.path.basename(src))
    # 校验是否存在
    while True:
        if os.path.exists(dst):
            dst = rename_file(dst)
        else:
            break
    try:
        shutil.copyfile(src, dst)
    except Exception as e:
        print("move failed:{},error source:{}".format(src, str(e)))


# 递归查找符合常见的文件格式的文件
def find_file(path):
    for file in os.listdir(path):
        temp_file = os.path.join(path, file)
        if os.path.isdir(temp_file):
            find_file(temp_file)
            print("dir:", temp_file)
        else:
            print("os.path.splitext(temp_file)[1][1:]", os.path.splitext(temp_file)[1][1:])
            if os.path.splitext(temp_file)[1][1:] in file_suffix:
                print("file:{}".format(temp_file))
                yid_data_to_move(temp_file)


if __name__ == '__main__':
    # 基础路径
    base_source = r""
    # 保存的路径
    base_dir = r""
    find_file(base_source)
    print("end of find")

标签:QQ,uuid,temp,微信,dst,file,path,拷贝,os
来源: https://www.cnblogs.com/ldsice/p/16506748.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有