Primary Detection (by header name):
- Selector: Searches for “selector” keyword (case-insensitive)
- Path: Searches for “path” keyword (case-insensitive)
- Duplicate_Index: Searches for “duplicate_index” keyword or exact “I”
Chapter-1-File-Organization-And-Backup
The Automated Duplicate File Mover is a comprehensive file management utility designed to process CSV reports containing duplicate file analysis and automatically move identified duplicate files to a secure staging area. This script provides an automated yet safe approach to duplicate file management, allowing users to efficiently clean up file systems while maintaining complete control over the deletion process.
This script is designed to work seamlessly as part of a comprehensive file management workflow: 1. File Discovery: Use File Listing Script to generate comprehensive file inventories 2. Duplicate Analysis: Process listings to identify and mark duplicate files 3. Safe Staging: Use this script to move duplicates to review area 4. Manual Review: Verify duplicates before permanent deletion 5. Final Cleanup: Delete staging folder after confirmation
The script requires one primary input:
A CSV file containing duplicate file analysis with specific column structure:
| Column Position | Expected Header | Alternative Names | Description | Required Values |
|---|---|---|---|---|
| A (1st) | Selector | Any first column | File classification | “DUPLICATE” for files to move |
| C (3rd) | Path | File Path, FilePath | Complete file system path | Valid accessible file paths |
| I (9th) | Duplicate_Index | Index, Count | Duplicate occurrence count | Integer > 1 for files to move |
Files are moved when both conditions are simultaneously met: - Column A (Selector) contains exactly “DUPLICATE” - Column I (Duplicate_Index) contains integer value > 1
The script features flexible column mapping:
python 03-find-and-delete-duplicates-v01.py.csv extension)The script automatically: - Folder Creation: Creates to_be_deleted folder in script directory - Permission Setup: Ensures proper write permissions - Path Validation: Confirms staging area accessibility - Status Reporting: Displays creation confirmation
The script performs: - Structure Analysis: Reads and analyzes CSV column structure - Column Mapping: Maps columns to expected data types - Criteria Application: Applies filtering logic (DUPLICATE + Index > 1) - Progress Reporting: Displays real-time processing status
For each qualifying file: - Existence Verification: Checks if file exists at specified path - Conflict Detection: Identifies potential filename conflicts - Safe Moving: Moves files to staging area with error handling - Naming Resolution: Applies numeric suffixes for conflicts - Operation Logging: Records all move operations
Location: ./to_be_deleted/ (created in script directory)
Contents: - All moved duplicate files with preserved original names - Conflict-resolved files with numeric suffixes (e.g., document_1.pdf, document_2.pdf) - Organized in flat structure for easy review
Naming Convention: - Original names preserved when no conflicts exist - Numeric suffixes applied for conflicts: filename_N.extension - Extension preservation maintains file type associations
File: ./move_report.txt (saved in script directory)
Duplicate File Move Report
==================================================
Total files moved: [number]
Files not found: [number]
Files with errors: [number]
SUCCESSFULLY MOVED FILES:
------------------------------
From: [original_file_path]
To: [destination_path_in_staging]
[Repeated for each successfully moved file]
FILES NOT FOUND:
--------------------
[path_of_missing_file_1]
[path_of_missing_file_2]
[Additional missing files...]
FILES WITH ERRORS:
--------------------
File: [problematic_file_path]
Error: [detailed_error_description]
[Repeated for each error encountered]
Processing Feedback: - Script initialization and version information - CSV file selection confirmation - Column detection results and mappings - Row-by-row processing status - File move confirmations or error messages - Operation summary with statistics
Example Console Output:
Duplicate File Mover
==================================================
Step 1: Select CSV file...
Selected CSV file: /path/to/duplicates.csv
Step 2: Creating 'to_be_deleted' folder...
Created folder: /script/directory/to_be_deleted
Step 3: Reading CSV and moving files...
CSV columns found: ['Selector', 'Filename', 'Path', ...]
Using columns: Selector='Selector', Duplicate_Index='I', Path='Path'
Processing row 15: /Users/documents/file1.pdf
Moved to: /script/directory/to_be_deleted/file1.pdf
Processing row 23: /Users/documents/file2.pdf
Moved to: /script/directory/to_be_deleted/file2_1.pdf
Processed 150 rows total
==================================================
OPERATION COMPLETE
==================================================
Files successfully moved: 12
Files not found: 2
Files with errors: 0
The script tracks and reports: - Successfully moved files: Count and detailed paths - Missing files: Files referenced in CSV but not found on disk - Error files: Files that couldn’t be moved due to permissions or other issues - Processing summary: Total rows processed vs. files moved
01-list-files-in-folder-v02.py to create comprehensive file listingsIf your CSV uses different column names: 1. Header-based detection: Script searches for keywords in headers 2. Position-based fallback: Uses standard column positions as backup 3. Manual verification: Console output shows detected column mappings 4. Error reporting: Clear messages if required columns aren’t found
To restore moved files: 1. Locate staging folder: Navigate to to_be_deleted directory 2. Reference move report: Use move_report.txt for original file locations 3. Manual restoration: Move files back to original locations as needed 4. Batch restoration: Use move report as reference for scripted restoration
Emergency recovery: - All original file paths preserved in move report - Files remain accessible and intact in staging area - No data loss occurs during move operations
Download all Python scripts and resources from this book:
All code examples, templates, and additional materials are available for download. Please do not share this link - Thank you.
Copyright © 2025 ChatBizDB.com. All rights reserved.
No part of this publication may be reproduced, distributed, or transmitted in any form or by any means, including photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law.
For permission requests, write to the publisher at: Email us
If you have any question or comment please contact us at Email us and make sure you add python-book at the beginning of the subject.
[1] "Time taken to run the Quarto document: 0.0911238193511963 seconds"