#文件去重
#参考: 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文件。
python文件按内容比较去重,编译成EXE可执行文件下载
最新推荐文章于 2024-10-15 11:38:32 发布