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

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4123|回复: 16
收起左侧

[Python 转载] 删除电脑微信目录下重复文件

  [复制链接]
zijing2270 发表于 2021-9-12 13:16
import os
import zlib
import time
import re
#递归文件夹
def recursionFolder(path):
    filename_regex = re.compile(r'.*\(\d+\)\..*')
    crcList=list()
    for root,dirs,files in os.walk(path):
        for file in files:
            print(os.path.join(root,file))
            temp = filename_regex.search(file)
            if temp != None:
                os.remove(os.path.join(root,file))
            if os.path.exists((os.path.join(root,file))):
                fileCRC=crc32(os.path.join(root,file))
                if fileCRC in crcList:
                    os.remove(os.path.join(root,file))
                else:
                    crcList.append(fileCRC)
#获取文件crc值
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)
recursionFolder("./")     #此处目录替换成自己电脑微信目录

免费评分

参与人数 6吾爱币 +6 热心值 +6 收起 理由
qinluezhew3 + 1 + 1 热心回复!
Daoying + 1 + 1 谢谢@Thanks!
shuaibi_chen + 1 + 1 谢谢@Thanks!
wuai1134288410 + 1 + 1 热心回复!
heiheixue3344 + 1 + 1 热心回复!
王金彪 + 1 + 1 谢谢@Thanks!

查看全部评分

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

halfone 发表于 2022-2-21 13:54
[Python] 纯文本查看 复制代码
import os
import zlib
import time
import re
#递归文件夹
def recursionFolder(path):
    filename_regex = re.compile(r'.*\(\d+\)\..*')
    crcList=list()
    for root,dirs,files in os.walk(path):
        for file in files:
            print(os.path.join(root,file))
            temp = filename_regex.search(file)
            if temp != None:
                os.remove(os.path.join(root,file))
            if os.path.exists((os.path.join(root,file))):
                fileCRC=crc32(os.path.join(root,file))
                if fileCRC in crcList:
                    os.remove(os.path.join(root,file))
                else:
                    crcList.append(fileCRC)
#获取文件crc值
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)
recursionFolder("./")     #此处目录替换成自己电脑微信目录

一名强迫症患者路过~
6967632632 发表于 2021-9-12 13:19
feiyucvb 发表于 2021-9-12 13:23
烟花非易冷 发表于 2021-9-12 13:25
看着很厉害,但是小白不会用。。
wwsw110 发表于 2021-9-12 13:32
不能弄个工具吗.....
augue 发表于 2021-9-12 13:40
厉害,我试试看
魔腿王 发表于 2021-9-12 13:44
厉害 我试试怎么样
7fMeteor 发表于 2021-9-12 13:51
挺不错的
aria1983 发表于 2021-9-12 16:08
bat批处理?
shuaibi_chen 发表于 2021-9-12 16:17
谢谢楼主分享
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

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

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

GMT+8, 2024-4-26 12:37

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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