Add a dry-run argument so the user can have the script detect duplicates without deleting them. This is useful for informing the user of which files would be deleted, should they run the script, normally.
24 lines
616 B
Python
24 lines
616 B
Python
#!/usr/bin/env python
|
|
|
|
# Duplicate Check
|
|
# Version: 0.12.0
|
|
|
|
# Copyright 2025 Jake Winters
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
import os
|
|
import hashlib
|
|
import argparse
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='Scan directory for duplicate files and delete them.')
|
|
parser.add_argument('--dry-run', '-d', action='store_true', help='Detect duplicates without deletion.')
|
|
|
|
|
|
def hash_file(file_path):
|
|
sha256_hash = hashlib.sha256()
|
|
with open(file_path, 'rb') as f:
|
|
for byte_block in iter(lambda: f.read(65536), b''):
|
|
sha256_hash.update(byte_block)
|
|
return sha256_hash.hexdigest() |