mirror of
https://github.com/xzb23/check_duplicate_files.git
synced 2026-11-24 18:45:31 +08:00
基础功能完成
This commit is contained in:
6 files changed
+77
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
__pycache__
|
||||||
|
dist
|
||||||
|
test
|
||||||
|
build
|
||||||
|
*.spec
|
||||||
|
*.backup
|
||||||
|
/.venv
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import os
|
||||||
|
import hashlib
|
||||||
|
import typing
|
||||||
|
import collections
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
from _in_package import *
|
||||||
|
from config import *
|
||||||
|
import common
|
||||||
|
import runing_data
|
||||||
|
|
||||||
|
|
||||||
|
def traverse_dir(root_dir):
|
||||||
|
for path, dirs, files in os.walk(root_dir):
|
||||||
|
path = common.formatting_path(path)
|
||||||
|
for filename in files:
|
||||||
|
runing_data.file_path_list.append(path + filename)
|
||||||
|
|
||||||
|
|
||||||
|
def hash_files_from_glist(algorithm: function):
|
||||||
|
for f_path in runing_data.file_path_list:
|
||||||
|
with open(f_path, "rb") as f:
|
||||||
|
f_hash = hashlib.file_digest(f, algorithm)
|
||||||
|
runing_data.file_hash_results.append(runing_data.FileHashResult(f_path, f_hash.hexdigest(), algorithm.__name__))
|
||||||
|
runing_data.hash_to_files[(f_hash.hexdigest(), algorithm.__name__)].append(f_path)
|
||||||
|
|
||||||
|
|
||||||
|
def print_info():
|
||||||
|
for t in runing_data.hash_to_files:
|
||||||
|
if len(runing_data.hash_to_files[t]) > 1:
|
||||||
|
print(t)
|
||||||
|
for fp in runing_data.hash_to_files[t]:
|
||||||
|
print("\t", fp)
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
work_dir = get_config("work_dir")
|
||||||
|
|
||||||
|
if not os.path.exists(work_dir):
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
|
traverse_dir(work_dir)
|
||||||
|
hash_files_from_glist(hashlib.sha256)
|
||||||
|
|
||||||
|
print_info()
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
from _in_package import *
|
||||||
|
from config import *
|
||||||
|
|
||||||
|
|
||||||
|
def formatting_path(path: str) -> str:
|
||||||
|
path = path.strip()
|
||||||
|
path = path.replace("\\", "/")
|
||||||
|
if path[-1] != "/":
|
||||||
|
path += "/"
|
||||||
|
return path
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
from _in_package import *
|
||||||
|
|
||||||
|
|
||||||
|
class FileHashResult(typing.NamedTuple):
|
||||||
|
filepath: str
|
||||||
|
hash_value: str
|
||||||
|
algorithm: str
|
||||||
|
|
||||||
|
|
||||||
|
file_path_list: list[str] = []
|
||||||
|
file_hash_results: list[FileHashResult] = []
|
||||||
|
|
||||||
|
# hash_to_files: { (hash_value, algorithm): [filepath, ...] }
|
||||||
|
hash_to_files: dict[tuple[str, str], list[str]] = collections.defaultdict(list)
|
||||||
Reference in new issue
Block a user