Files
P2EP_Export/UnRLE/0864_Btl_CONTC/duplicates.py
2025-12-09 21:20:05 +05:00

30 lines
929 B
Python

import os
import json
import hashlib
# Создаем словарь для группировки
file_groups = {}
# Ищем все .txt файлы
for filename in [f for f in os.listdir('.') if f.endswith('.txt') and os.path.isfile(f)]:
try:
with open(filename, 'rb') as f:
content = f.read()
file_hash = hashlib.md5(content).hexdigest()
# Добавляем в группу
file_groups.setdefault(file_hash, []).append(filename)
except:
pass
# Преобразуем в нужный формат
result = list(file_groups.values())
# Сохраняем в JSON
with open("contacts_copy.json", 'w') as f:
json.dump(result, f, indent=2)
# Выводим статистику
print(f"Найдено файлов: {sum(len(g) for g in result)}")
print(f"Создано групп: {len(result)}")
print(f"Сохранено в contacts_copy.json")