This Python script helps you find and remove duplicate files in a directory. It identifies potential duplicate files based on patterns in their names (like '(1)', '(2)', '.copy', ' - copy', etc.). It groups files that reduce to the same base name after pattern removal and keeps the oldest version of each file group based on creation time, marking the others for deletion.
- Finds duplicate files based on name patterns.
- Supports custom regular expression patterns for identifying duplicates.
- Detects and handles ".copy" and " - copy" patterns.
- Recursive directory scanning.
- Dry-run mode to preview changes before deleting files.
- Interactive mode for easy configuration.
The script can be run from the command line or in interactive mode.
python duplicates_remove_v6.py <directory> [options]<directory>: The directory to scan (default: current directory).--dry-runor-d: Only report files that would be deleted without actually deleting.--patternor-p: Regular expression pattern to match numerical duplicate indicators (default: '\s*(\d+)').--yesor-y: Skip confirmation prompt (use with extreme caution).--copyor-c: Also detect files ending with '.copy' or ' - copy' (case-insensitive).--recursiveor-r: Recursively scan subdirectories.
Example:
python duplicates_remove_v6.py ~/Downloads --recursive --copy --yesRun the script without any arguments to start interactive mode. The script will prompt you for the directory to scan, whether to detect ".copy" and " - copy" patterns, and whether to scan subdirectories recursively.
python duplicates_remove_v6.py- Python 3.6 or higher
- click (External dependency:
pip install click) - loguru (External dependency:
pip install loguru) - send2trash (External dependency:
pip install send2trash)
iSams123
This project is licensed under the MIT License.
-
clean_empty_dir.py: Recursively finds and deletes empty directories. It uses theclicklibrary to provide a command-line interface with options for a dry run and skipping the confirmation prompt. -
clean_empty_dir_deepseek.py: Recursively finds and removes empty directories. It usesclickfor the command-line interface,logurufor logging, andsend2trashto send directories to the trash instead of permanently deleting them by default. It also provides options for forcing permanent deletion and increasing verbosity.