Smart File Organizer
Organize cluttered local folders (such as Downloads or Desktop) safely using organize.py and cleanup.py. Built with Python 3.8+ standard library only—no third-party packages required.
Golden Safety Rules
- NEVER skip the dry-run preview. Always run
plan(orclean-scan) and show the user a clear summary before changing anything. - NEVER pass
--yesbefore explicit user approval. Only runapply --yesorclean-apply --yesafter the user confirms the exact previewed items. - NEVER delete any regular user file.
plan/applynever deletes any file (duplicates are only quarantined into_Duplicates/_重复文件when requested).clean-scan/clean-applyis strictly locked to a hardcoded whitelist: ONLY.tmp/.tempfiles,temp/tmpfolders (plus opt-in%TEMP%via--include-user-temp), truly empty folders (os.rmdir), and corresponding stale WindowsHKCUregistry entries. It will NEVER touch.txt,.log,.bak, documents, or existing files.
- Always provide the exact rollback command (
undoorclean-undo) after runningapplyorclean-apply.
Workflow A: Organize Files
Step 1: Confirm Target & Preferences
Confirm the target directory path and infer or ask for:
- Mode:
by-type(default),by-date,by-type-date, orby-extension - Folder language:
--lang zh(when user speaks Chinese or prefers Chinese folder names) or--lang en - Scope: top-level only (default) or
--recursive - Duplicates: whether to isolate exact duplicates (
--quarantine-duplicates)
For full rules, extension mappings, and custom JSON rule schema, see rules-and-safety.md and custom-rules.example.json.
Step 2: Scan the Folder
python scripts/organize.py scan "<target_dir>" --lang zh
Step 3: Generate & Present a Dry-Run Plan
python scripts/organize.py plan "<target_dir>" --mode by-type --lang zh --quarantine-duplicates --plan-out "<temp_dir>/organize-plan.json"
Present the destination folder summary and sample moves. Wait for explicit user confirmation.
Step 4: Apply & Verify
python scripts/organize.py apply "<target_dir>" --plan "<temp_dir>/organize-plan.json" --yes
Give the user the exact undo command printed by apply.
Workflow B: Optional Cleanup (Temp + Empty Folders + Corresponding Registry)
This workflow can be offered after organizing a folder or run standalone when requested.
Step 1: Ask Whether the User Wants Cleanup & Confirm Scope
Ask the user:
- Whether they want to scan for temp files/folders (
.tmp/.temp,temp/tmp), truly empty folders, and corresponding stale Windows HKCU registry entries inside<target_dir>. - Whether to also scan their user OS
%TEMP%folder (--include-user-temp, opt-in only; never touchesC:\Windows\Temp).
Step 2: Run clean-scan (Dry-Run Preview)
python scripts/organize.py clean-scan "<target_dir>" --plan-out "<temp_dir>/cleanup-plan.json"
Add --recursive to scan nested temp items, or --include-user-temp if explicitly requested. Use --temp, --empty-dirs, or --registry to limit to specific categories.
Present the full categorized preview to the user:
[1]Temp files & temp folders (names, counts, total size)[2]Truly empty folders[3]Matching stale HKCU registry entries (key label, value name, stale path)
Step 3: Ask for Explicit User Consent
STOP and ask the user for approval. They may approve all three categories, approve only some (e.g. temp + empty folders without registry, or vice versa), or cancel.
Step 4: Execute Approved Cleanup (clean-apply --yes)
If the user approves the full saved plan:
python scripts/organize.py clean-apply "<target_dir>" --plan "<temp_dir>/cleanup-plan.json" --yes
If the user deselected any category, re-run with only the approved flags (e.g. --temp --empty-dirs) and --yes.
Step 5: Report Results & Rollback Command
Report:
- Counts of removed temp files/dirs, empty folders, and registry entries (plus any skipped busy/locked items)
- The
.regbackup file location inside<target_dir>/.organizer-logs/ - The exact
clean-undocommand to restore removed empty folders and backed-up registry entries:
python scripts/organize.py clean-undo "<target_dir>" --run-id <run_id>
Additional Commands
- Find exact duplicates only:
python scripts/organize.py duplicates "<target_dir>" --recursive - Check organize & cleanup history:
python scripts/organize.py history "<target_dir>" - Undo organization:
python scripts/organize.py undo "<target_dir>" - Undo cleanup (empty folders + registry):
python scripts/organize.py clean-undo "<target_dir>"