Python帮你解决手机qq微信内存占用太多问题
作者:迢迢x 时间:2023-04-02 18:14:44
导语:
哈喽,哈喽~大家有没有遇到过这种情况,手机用着用着没有内存了,一到设置里面一看。
微信和 QQ 10G!
啊这。。。。。就离谱!好说,好说,设置中都有一个清除数据的功能,一键下去内存暂时都回来了,但是宝,你确定你微信和QQ中的信息都没用吗?
下面能小编就用 Python 写个删除重复文件的脚本清理这些微信和QQ空间。确保在清除内存的时候,你的重要信息还在。
正文:
glob 模块
glob 模块非常简单,就是用来查找文件和文件夹。查找文件只用到三个匹配符:"*", "?", "[]"。
通配符 功能
*:匹配0或多个字符
**:匹配所有文件,目录,子目录和子目录里面的文件
?:匹配一个字符,这里与正则表达式? (正则?匹配前面表达式0次或者1次)
[]:匹配指定范围内的字符,如: [1-9]匹配1至9内的字符
[!]:匹配不在指定范围内的字符
glob方法
这个方法返回所有匹配的文件路径列表
# 当前路径下所有 py 文件
for fname in glob.glob("**/*.py",recursive=True):
print(fname)
# 当前路径文件 py 下 py 文件
for fname in glob.glob("py/*.py"):
print(fname)
# 单字通配符 ?,当前路径文件下以 Tem 开头后有一个字符文件夹
for fname in glob.glob("Tem?"):
print(fname)
# 范围通配符[],当前路径文件下以 Tem 开头后一个数字符的 py 文件
for fname in glob.glob("Tem[0-9].py"):
print(fname)
# 范围通配符[!],当前路径文件下以 Tem 开头后一个非数字符的 py 文件
for fname in glob.glob("Tem[!0-9].py"):
print(fname)
windowns下
file = glob.glob(r'D:\logs\*\*'
zlib.crc32
CRC32 算法概述 CRC 全称 Cyclic Redundancy Check,又叫循环冗余校验。和 md5 码一样都是 hash 的。当两个文件内容的 CRC32 相同的时候,这个文件也就是相同的。反之,两个文件就是不同的文件。
def crc32(file_path):
with open(file_path, 'rb') as fh:
hash = 0
while True:
s = fh.read(65536)
if not s:
break
hash = zlib.crc32(s, hash)
return "%08X" % (hash & 0xFFFFFFFF)
去重复
看到这里,想必都明白如何去重复文件了:
1. 用 glob.glob 扫描所有文件,
2. 把文件的 crc32 值放入字典中,
3. 找到字典中已经存在的 crc32 值的key,删除当前文件。
import os
import zlib
import glob
def scanning_floder(glob_path):
crc32Dict = {}
for fname in glob.glob(glob_path, recursive=True):
if os.path.isfile(fname):
crc = crc32(fname)
if crc in crc32Dict:
print('已经存在文件:' + crc32Dict.get(crc))
print('重复文件:' + fname)
print('删除文件:' + fname)
os.remove(fname)
print('')
else:
crc32Dict[crc] = fname
def crc32(file_path):
with open(file_path, 'rb') as f:
hash = 0
while True:
s = f.read(1024)
if not s:
break
hash = zlib.crc32(s, hash)
return "%08X" % (hash & 0xFFFFFFFF)
scanning_floder(r"C:\Users\xxxx\Documents\WeChat Files\xxxx\FileStorage\**\*")
来源:https://blog.csdn.net/a55656aq/article/details/122473658
标签:Python,qq微信内存占用,手机内存清理
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中tkinter无法同时显示多个image的解决方法及pack与place解析
2021-05-10 10:23:47
![](https://img.aspxhome.com/file/2023/2/135272_0s.png)
15行Python代码实现免费发送手机短信推送消息功能
2023-11-01 10:20:51
![](https://img.aspxhome.com/file/2023/7/97187_0s.jpg)
python中with的具体用法
2021-12-08 17:41:16
PyTorch中clone()、detach()及相关扩展详解
2022-06-29 17:50:34
CSS实现完美垂直居中
2007-09-22 09:29:00
PyQt5实现五子棋游戏(人机对弈)
2022-05-22 12:00:50
![](https://img.aspxhome.com/file/2023/4/96964_0s.jpg)
js为什么[]==![]是成立的吗
2024-04-10 16:10:34
对tensorflow中的strides参数使用详解
2022-06-12 06:00:38
golang 防缓存击穿singleflight的实现
2024-05-09 09:55:23
利用Python找回微信撤回信息
2022-11-21 22:34:03
![](https://img.aspxhome.com/file/2023/4/135424_0s.jpg)
K8ssandra入门教程之Linux上部署K8ssandra到Kubernetes的过程
2022-04-02 03:12:59
![](https://img.aspxhome.com/file/2023/8/120548_0s.jpg)
Python 列表(list)的常用方法
2022-05-04 19:05:20
![](https://img.aspxhome.com/file/2023/7/95167_0s.png)
在Python的struct模块中进行数据格式转换的方法
2021-09-26 14:24:40
![](https://img.aspxhome.com/file/2023/6/101176_0s.jpg)
Access数据库出现0x80004005问题的解决方法
2008-11-28 14:25:00
Python模块的制作方法实例分析
2021-09-06 05:57:26
uniapp中微信小程序与H5相互跳转以及传参详解(webview)
2024-04-10 16:20:37
![](https://img.aspxhome.com/file/2023/9/136699_0s.png)
Python随机生成带特殊字符的密码
2021-10-07 02:48:05
Python3 Tkinkter + SQLite实现登录和注册界面
2023-10-01 14:56:15
![](https://img.aspxhome.com/file/2023/5/62945_0s.jpg)
Python爬虫基础之XPath语法与lxml库的用法详解
2022-07-03 20:56:06
![](https://img.aspxhome.com/file/2023/3/90893_0s.png)
centos 安装mysql中遇到问题的解决办法
2010-12-14 15:11:00