python文件按内容比较去重,编译成EXE可执行文件下载

#文件去重
#参考: https://blog.csdn.net/qq_43965708/article/details/119516231?utm_medium=distribute.pc_category.none-task-blog-hot-2.nonecase&depth_1-utm_source=distribute.pc_category.none-task-blog-hot-2.nonecase

from pathlib import Path
import  filecmp
import os
path = os.getcwd()
print('当前程序路径为:', path)
print('比较程序目录下test目录中的文件内容,删除重复文件 ')
path_list = [path for path in Path(r'test').iterdir() if path.is_file()]
#  shallow=True ,只比较文件名及创建时间。False,比较文件内容。
s = str(input('如果程序继续执行,将删除test目录下内容相同的重复文件,请确认继续执行吗? (Y/N):'))
if s =='Y' or s=='y':
    for front in range(len(path_list)-1):
       for later in range(front +1,len(path_list)):
           if filecmp.cmp(path_list[front],path_list[later],shallow=False):
             path_list[front].unlink()
             break
print('程序执行结束!')

#将文件打包成单独可执行exe文件 ,先确认是否安装 pyinstaller : pip install pyinstaller .
# 执行打包命令:需要在DOS窗口,到py程序所在目录中。
# pyinstaller -F 文件去重.py
#在目录中新产生几个文件夹,其中dist目录中为打包好的可执行EXE文件。

打包好的EXE文件下载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值