吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 8346|回复: 56
收起左侧

[原创工具] 【微信和企业微信缓存自动清理缓存】python语言编写

[复制链接]
VIP88888888 发表于 2021-6-15 12:00
本帖最后由 VIP88888888 于 2021-6-17 15:30 编辑

原创软件请大家多多给些意见或建议谢谢!


软件主要功能是自动通过判断注册表、微信配置文件和手动输入判断企业微信和微信的缓存目录,并自动清理不重要数据
由于微信和企业机制问题部分电脑不能自动识别缓存目录,
目前只能通过微信默认缓存、微信自带配置文件、注册表判断缓存目录,如果有大神发现有更高效的方法,可以我留言
只能手动输入缓存目录,第一次手动输入后下次会自动读取配置文件



微信缓存目录

微信缓存目录

微信缓存目录


企业微信缓存目录

企业微信缓存目录

企业微信缓存目录






成品:
百毒云:
链接:https://pan.baidu.com/s/1G84Hc-8s2zPzT7FHv8Tw8A
提取码:52pj

蓝奏云
链接:https://wwr.lanzoui.com/iLTtiqa0acd
密码:cdzp

软件界面
image.png


2021/6/17日更新:
1、增加电脑盘符判断,避免某些电脑没有D盘导致闪退
2、增加微信清理目录,将微信缓存删除得更彻底
3、增加异常捕获,减少闪退

源代码:
[Python] 纯文本查看 复制代码
import os
import re
import string
import shutil
import winreg
from time import sleep
from pathlib import Path
import configparser



def get_disklist():
    disk_list = []
    for c in string.ascii_uppercase:
      disk = c + ':'
      if os.path.isdir(disk):
        disk_list.append(c)
    Path(disk_list[-1]+':/wx_path.ini').touch()
    return disk_list[-1]

# 记录一下所有垃圾的总大小
total_trash_size = 0
disk_data = get_disklist()

def get_reg_dir(software):
    if software == "微信":
        try:
            string = r'SOFTWARE\Tencent\WeChat'
            handle = winreg.OpenKey(winreg.HKEY_CURRENT_USER, string, 0, (winreg.KEY_WOW64_64KEY + winreg.KEY_READ))
            location, _type = winreg.QueryValueEx(handle, "FileSavePath")
            return location

        except :
            return False
    elif software == "企业微信":
        try:
            string = r'SOFTWARE\Tencent\WXWork'
            handle = winreg.OpenKey(winreg.HKEY_CURRENT_USER, string, 0, (winreg.KEY_WOW64_64KEY + winreg.KEY_READ))
            location, _type = winreg.QueryValueEx(handle, "DataLocationPath")
            return location

        except :
            return False

def get_software_dir(software):
    if software == "微信":
        if os.path.exists(disk_data+':/wx_path.ini'):
            try:
                cf = configparser.ConfigParser()
                cf.read(disk_data+':/wx_path.ini',encoding='utf-8')
                wx_path = cf.get("weixin","wx_path")
                return Path(wx_path)
            except Exception as e:
                print(e)
                if Path(Path.home() / "Documents" / "WeChat Files").is_file():
                    
                    wx_path = Path(Path.home() / "Documents" / "WeChat Files")
                    return Path(wx_path)

                if os.path.exists(Path.home() /'AppData'/'Roaming'/'Tencent'/'WeChat'/'All Users'/'config'/'3ebffe94.ini'): 
                    try:
                        with open(Path.home() /'AppData'/'Roaming'/'Tencent'/'WeChat'/'All Users'/'config'/'3ebffe94.ini', "r") as f:  # 打开文件
                            wx_path = Path(str(f.read())+"/WeChat Files")   # 读取文件
                        if os.path.exists(wx_path):
                            return wx_path
                    except Exception as e:
                        print(e)

                if os.path.exists(Path.home() /'AppData'/'Roaming'/'Tencent'/'WeChat'/'All Users'/'config'/'b928cd74.ini'):
                    try:
                        with open(Path.home() /'AppData'/'Roaming'/'Tencent'/'WeChat'/'All Users'/'config'/'b928cd74.ini', "r") as f:  # 打开文件
                                wx_path = Path(str(f.read())+"/WeChat Files")   # 读取文件
                        if os.path.exists(wx_path):
                            return wx_path
                    except Exception as e:
                        print(e)
                
                if get_reg_dir("微信"):
                    return Path(get_reg_dir("微信"))
                wx_path = Path(input("未找到微信缓存目录!请手动输入:"))
                try:
                    os.chdir(disk_data+':/')
                    cf = configparser.ConfigParser()
                    cf.add_section("weixin")
                    cf.set("weixin","wx_path",str(wx_path))
                    with open(disk_data+':/wx_path.ini',"a") as f:
                        cf.write(f)
                except Exception as e:
                    print(e)
                return Path(str(wx_path))
            
        else:
            wx_path = Path(input("未找到微信缓存目录!请手动输入:"))
            try:
                Path(disk_data+':/wx_path.ini').touch()
                os.chdir(disk_data+':/')
                cf = configparser.ConfigParser()
                cf.add_section("weixin")
                cf.set("weixin","wx_path",str(wx_path))
                with open(disk_data+':/wx_path.ini',"a") as f:
                    cf.write(f)
            except Exception as e:
                print(e)
            return Path(str(wx_path))


    
    elif software == "企业微信":
        if os.path.exists(disk_data+':/wx_path.ini'):
            try:
                cf = configparser.ConfigParser()
                cf.read(disk_data+':/wx_path.ini',encoding='utf-8')
                qywx_path = cf.get("qyweixin","qywx_path")
                return Path(qywx_path)
            except Exception as e:
                print(e)
                if Path(Path.home() / "Documents" / "WXWork").is_file():
                    wkchat_dir = Path(Path.home() / "Documents" / "WXWork")
                    return wkchat_dir
                if get_reg_dir("企业微信"):
                    return Path(get_reg_dir("企业微信"))
                qywx_path = Path(input("未找到企业微信缓存目录!请手动输入:"))
                try:
                    os.chdir(disk_data+':/')
                    cf = configparser.ConfigParser()
                    cf.add_section("qyweixin")
                    cf.set("qyweixin","qywx_path",str(qywx_path))
                    with open(disk_data+':/wx_path.ini',"a") as f:
                        cf.write(f)
                except Exception as e:
                    print(e)
                return Path(qywx_path)
        else:
            qywx_path = Path(input("未找到微信缓存目录!请手动输入:"))
            try:
                Path(disk_data+':/wx_path.ini').touch()
                os.chdir(disk_data+':/')
                cf = configparser.ConfigParser()
                cf.add_section("qyweixin")
                cf.set("qyweixin","qywx_path",str(qywx_path))
                with open(disk_data+':/wx_path.ini',"a") as f:
                    cf.write(f)
            except Exception as e:
                print(e)
            return Path(qywx_path)


def remove_wxtrash():
    """删除微信的所有缓存"""
    global total_trash_size
    # 找到微信的存储目录
    wechat_dir = get_software_dir("微信")
    print(wechat_dir)
    # 记录所有垃圾文件和文件夹的路径,用来之后进行删除
    trash_list = []

    print('开始扫描微信的缓存文件...')
    print('=' * 30)
    # All Users 目录存储了所有登录过的用户使用过的头像
    trash_list.extend(find_trash(Path(os.environ.get('USERPROFILE') +'/AppData/Local/Temp'), title='系统缓存文件'))
    trash_list.extend(find_trash(wechat_dir / "All Users", '*', '已登录过用户的头像图片'))
    # Applet 目录存储了所有小程序的缓存
    trash_list.extend(find_trash(wechat_dir / "Applet", '*', '公用小程序缓存'))
    # 获取所有登录过的用户产生的缓存文件
    for d in wechat_dir.iterdir():
        if d.name not in ['Applet', 'All Users']:
            try:
                name = re.split("\\\\",str(d))[-1]
                print(f'{name} 的目录下,共发现:')
            except :
                pass
            trash_list.extend(find_trash(d / 'Applet', title='用户小程序缓存',indent=1))
            
            # Attachment,Backup,BackupFiles,CustomEmotions 都是空的
            # Data 不知道干什么用的,但是不大,先不删了
        
            # FavTemp 不知道是什么,但是应该没用,可以删
            trash_list.extend(find_trash(d / 'FavTemp', title='其他缓存',indent=1))
        
            # 表情包文件缓存
            trash_list.extend(find_trash(d / 'CustomEmoV1', title='表情文件缓存'))
            
            trash_list.extend(find_trash(d / 'ResUpdate', title='更新缓存文件',indent=1))
            
            trash_list.extend(find_trash(d / 'ResUpdateV2', title='其他垃圾文件',indent=1))
            
            trash_list.extend(find_trash(d / 'FileStorage' , title='缓存文件',indent=1))
            

    print('=' * 30)
    print(f'总垃圾大小:{total_trash_size:.3f} MB')

    # print('请注意,以上垃圾包含所有下载(点开)过的图片、视频、文本文件,请谨慎删除!')
    # user_input = input('是否清除全部垃圾?y(es)/n(o) > ')
    # if user_input.lower() not in ['y', 'yes']:
    #     return
    
    print('开始清理垃圾...')
    for p in trash_list:
        if not remove_file_or_folder(p):
            total_trash_size -= get_size(p)
    print(f'本次共清理微信垃圾 {total_trash_size:.3f} MB')


def remove_wktrash():
    """删除企业微信的所有缓存"""
    global total_trash_size
    # 找到微信的存储目录
    wkchat_dir = get_software_dir("企业微信")
    print(wkchat_dir)
    # 记录所有垃圾文件和文件夹的路径,用来之后进行删除
    trash_list = []

    print('开始扫描企业微信的缓存文件...')
    print('=' * 30)
    # All Users 目录存储了所有登录过的用户使用过的头像
    
    for d in wkchat_dir.iterdir():
        try:
            name = re.split("\\\\",str(d))[-1]
            print(f'{name} 的目录下,共发现:')
        except :
            pass
        trash_list.extend(find_trash(d / "Avator", '*', '已登录过用户的头像图片',indent=1))

        # Applet 目录存储了所有小程序的缓存
        trash_list.extend(find_trash(d / "Cache", '*', '缓存',indent=1))
        
        trash_list.extend(find_trash(d / "Emotion", '*', '表情包',indent=1))
        
        trash_list.extend(find_trash(d / "WeDrive", '*', '网盘文件',indent=1))
    print('=' * 30)
    print(f'总垃圾大小:{total_trash_size:.3f} MB')

    # print('请注意,以上垃圾包含所有下载(点开)过的图片、视频、文本文件,请谨慎删除!')
    # user_input = input('是否清除全部垃圾?y(es)/n(o) > ')
    # if user_input.lower() not in ['y', 'yes']:
    #     return
    
    print('开始清理垃圾...')
    for p in trash_list:
        if not remove_file_or_folder(p):
            total_trash_size -= get_size(p)
    print(f'本次共清理企业微信垃圾 {total_trash_size:.3f} MB')



def find_trash(d: Path, glob='*', title='缓存', indent=0):
    """获取某个垃圾文件夹的信息"""
    if not d.exists():
        return []
    global total_trash_size
    total_size = 0
    trash_list = []
    for p in d.glob(glob):
        total_size += get_size(p)
        trash_list.append(p)
    # 如果传入 title 为空,则不输出信息,仅记录垃圾文件的路径
    if not title:
        return trash_list
    # 开头的缩进
    if indent > 0:
        title = '\t' * indent + title
    # 输出信息
    print(f'{title}:{total_size:.3f} MB')
    total_trash_size += total_size
    return trash_list


def remove_file_or_folder(p: Path):
    """删除文件或文件夹"""
    try:
        if p.is_file():
            p.unlink()
        elif p.is_dir():
            shutil.rmtree(p.absolute())
        else:
            # 见鬼去吧
            pass
        return True
    except:
        print(f'无法删除 {p.absolute()}')
        return False


def get_size(p: Path):
    """获取一个文件或文件夹的大小"""
    # 如果是文件
    if p.is_file():
        return p.stat().st_size / 1048576  # 以 MB 为单位
    # 如果是文件夹
    elif p.is_dir():
        # 获取其下所有文件的大小之和
        return sum([get_size(f) for f in p.rglob('*') if f.is_file()])
    # 我不知道除了文件和文件夹以外还有别的什么类型,但是如果有,让它见鬼去吧
    return 0


if __name__ == "__main__":
    remove_wxtrash()
    sleep(5)
    remove_wktrash()    sleep(20)

免费评分

参与人数 8吾爱币 +13 热心值 +7 收起 理由
rock1102 + 1 + 1 热心回复!
倒霉的外星人 + 1 + 1 热心回复!
bittersweet0 + 1 谢谢@Thanks!
novary + 1 热心回复!
HY清风 + 1 + 1 不够智能,改过目录的,提示未找到
风之暇想 + 7 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
xaibin + 1 + 1 谢谢@Thanks!
Hacker丶狂少 + 1 + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

默默默默陌 发表于 2021-6-15 13:03
谢谢分享 不过感觉不太实用  现在很多手机都有这功能
 楼主| VIP88888888 发表于 2021-6-24 23:05
yoyoma211 发表于 2021-6-24 18:36
这个感觉满给力的,是不是微信默认都装在c盘,缓存也都在c盘哈?

TEMP目录是在C盘,微信缓存默认在用户文档目录下的
360204878 发表于 2021-6-15 12:22
头像被屏蔽
youximang 发表于 2021-6-15 13:09
提示: 作者被禁止或删除 内容自动屏蔽
风夜 发表于 2021-6-15 14:06
清理的是PC版的吗?
6565668 发表于 2021-6-15 14:18
正好需要,感谢
wangzhenuen 发表于 2021-6-15 14:26
有成品吗?
 楼主| VIP88888888 发表于 2021-6-15 15:19
风夜 发表于 2021-6-15 14:06
清理的是PC版的吗?

对的是pc版的哦
 楼主| VIP88888888 发表于 2021-6-15 15:20

链接:https://pan.baidu.com/s/1G84Hc-8s2zPzT7FHv8Tw8A
提取码:52pj
8204118 发表于 2021-6-15 15:37
这个是安卓的??
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 提醒:禁止复制他人回复等『恶意灌水』行为,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-3-29 21:04

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表