蜻蜓手游网,分享真实精致软件资源!

微信缓存自动清理工具 1.0 Python版

  • 微信缓存自动清理工具
  • 大小:

    7.3M
  • 时间:

    2021-06-15 15:49
  • 语言:

    中文
  • 版本:

    1.0 Python版
  • 等级:

    4级
  • 平台:

    Windows
  • 类别:

    官方版/ 免费 /其他软件
  • 官网:

    暂无
  • 厂商:

好评:50%
坏评:50%
扫描二维码下载到手机
微信缓存自动清理工具1.0 Python版截图0

微信缓存自动清理工具介绍

相信很多小伙伴都知道,软件在使用的过程中都会产生缓存数据的,而且长期不清理会导致占用空间越来越大,可能影响电脑的运行速度,我们常用的微信也是这样,微信缓存自动清理工具采用python语言编写,不需要安装,支持自动清理微信所产生的缓存,并且不会删除重要数据。

微信缓存自动清理工具

微信缓存自动清理工具特色

自动通过注册表、微信配置文件和手动输入判断企业微信和微信的缓存目录,并自动清理不重要数据

微信缓存自动清理工具代码

import os

import re

from time import sleep

import shutil

import winreg

from pathlib import Path

import configparser

 

# 记录一下所有垃圾的总大小

total_trash_size = 0

 

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('D:/wx_path.ini'):

            try:

                cf = configparser.ConfigParser()

                cf.read('D:/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("未找到微信缓存目录!请手动输入:"))

                os.chdir('D:/')

                cf = configparser.ConfigParser()

                cf.add_section("weixin")

                cf.set("weixin","wx_path",str(wx_path))

                with open('D:/wx_path.ini',"a") as f:

                    cf.write(f)

                return Path(str(wx_path))

        else:

            Path('D:/wx_path.ini').touch()

            wx_path = Path(input("未找到微信缓存目录!请手动输入:"))

            os.chdir('D:/')

            cf = configparser.ConfigParser()

            cf.add_section("weixin")

            cf.set("weixin","wx_path",str(wx_path))

            with open('D:/wx_path.ini',"a") as f:

                cf.write(f)

            return Path(str(wx_path))

 

 

     

    elif software == "企业微信":

        if os.path.exists('D:/wx_path.ini'):

            try:

                cf = configparser.ConfigParser()

                cf.read('D:/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("未找到企业微信缓存目录!请手动输入:"))

                os.chdir('D:/')

                cf = configparser.ConfigParser()

                cf.add_section("qyweixin")

                cf.set("qyweixin","qywx_path",str(qywx_path))

                with open('D:/wx_path.ini',"a") as f:

                    cf.write(f)

                return Path(qywx_path)

        else:

            Path('D:/wx_path.ini').touch()

            qywx_path = Path(input("未找到微信缓存目录!请手动输入:"))

            os.chdir('D:/')

            cf = configparser.ConfigParser()

            cf.add_section("qyweixin")

            cf.set("qyweixin","qywx_path",str(qywx_path))

            with open('D:/wx_path.ini',"a") as f:

                cf.write(f)

            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))

             

            # Image, Video, Files 都是空的

            # 其下是以形如 2020-06 的文件夹存储的各种图片缩略图缓存文件

            trash_list.extend(find_trash(d / 'FileStorage' / 'Cache', title='缩略图文件',indent=1))

            # 又又又一个表情图片缓存

            trash_list.extend(find_trash(d / 'FileStorage' / 'CustomEmotion', title='自定义表情文件缓存',indent=1))

            # 下载到本地的文件

            trash_list.extend(find_trash(d / 'FileStorage' / 'File', title='已下载文件',indent=1))

            # 未知缓存文件,在微信运行中被占用,无法删除

            trash_list.extend(find_trash(d / 'FileStorage' / 'Fav', title='未知文件',indent=1))

            # 图片文件

            trash_list.extend(find_trash(d / 'FileStorage' / 'Image', title='图片数据文件',indent=1))

            # 视频文件

            trash_list.extend(find_trash(d / 'FileStorage' / 'Video', title='视频文件',indent=1))

            # 表情包图标文件

            trash_list.extend(find_trash(d / 'FileStorage' / 'General' / 'Data', title='表情图标文件',indent=1))

            # 高清头像图片

            trash_list.extend(find_trash(d / 'FileStorage' / 'General' / 'HDHeadImage', title='高清头像图片',indent=1))

            # ResUpdate 里面只有损坏的压缩包,不知道是干什么用的,但肯定没卵用

 

    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):

            print(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): 

            print(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)

什么是缓存?

缓存指在下载过程中暂时存放数据的一块内存区域。缓存能够有效的避免程序对硬盘进行频繁地写操作。是指临时文件交换区,手机把最常用的文件从存储器里提出来临时放在缓存里,就像把工具和材料搬上工作台一样,这样会比用时现去仓库取更方便。因为缓存往往使用的是RAM,断电即掉的非永久储存,所以在忙完后还是会把文件送到手机存储器里。缓存能够有效的避免电驴程序对硬盘进行频繁地写操作,因为当你设置了缓存以后,只有暂存的数据达到指定大小以后才会被写入硬盘。

应用信息

其他版本

猜你喜欢

    热门评论

    最新评论

    发表评论查看所有评论(0)

    昵称:
    表情: 高兴 可 汗 我不要 害羞 好 下下下 送花 屎 亲亲
    字数: 0/500 (您的评论需要经过审核才能显示)

    最新合集