Safety-oriented Windows disk cleanup:Analyze → Simulate → Execute → Verify, always preview destructive operations first.
Acceptance criteria (self-check before a cleanup task is complete)
- A simulation run was completed before the actual deletion, and the preview results were shown to the user
-
--executeThe user explicitly confirmed beforehand (cleanup does not go through the Recycle Bin and is unrecoverable) - The user was reminded to create a system restore point and close the browser (when clearing cache)
- No directory in the "Do Not Delete List" was touched
- After cleanup, rerun the analysis and reportthe actual amount of space freed, not "should have been cleaned"
- The user's personal large files (videos/archives, etc.) are only reported by location and size; the user decides whether to delete them
Do Not Delete List (stop on contact)
C:\Windows\System32— core system filesC:\Windows\WinSxS— Windows component store (to slim it down use DISM; do not delete directly)C:\Program Files/C:\ProgramData— installed programs and dataC:\Windows\Prefetch— prefetch files; deleting them slows down startup- Hibernation file and virtual memory — adjust via system settings; do not manually delete the files
Workflow
1. Analyze usage
python scripts/analyze_disk.py C:\ 2 20 # 路径 深度 显示前N项
2. Find large files (report only, do not delete)
python scripts/find_large_files.py C:\ 100 50 # 路径 最小MB 最大结果数
python scripts/find_large_files.py C:\Users 200 100 .mp4,.avi,.mkv # 按类型过滤
Common large file types: videos .mp4,.mkv,.mov; installers .iso,.exe,.msi; archives .zip,.rar,.7z; backups .bak,.sql。
3. Cleanup (simulation mode by default)
python scripts/clean_temp.py # 模拟:只预览
python scripts/clean_temp.py --execute # 实际执行:需二次确认
Coverage:%TEMP%、C:\Windows\Temp, browser caches (Chrome/Edge/Firefox),.log/.etl/.old logs, Recycle Bin.
4. Verify
Rerun analyze_disk.py, compare the before and after numbers, and report the actual effect.
Known pitfalls
| Pitfall | Symptom | Countermeasure |
|---|---|---|
| Silent missed scans due to lack of permissions | Running as non-administrator makes scan results smaller and misleads judgment | Prompt to run as administrator; the script skips directories without permission and counts them |
| Browser cache cleanup fails | Browser processes are occupying the files | Close all browser windows before cleaning |
| No effect after cleaning | Temporary files were not large to begin with; the bulk is personal files or programs | Go back to the large file report and directory ranking, and guide the user to decide (uninstall/transfer) |
| Mistakenly thinking it is recoverable | Script deletion does not go through the Recycle Bin | Clearly state before execution that it is unrecoverable; this is also why simulation comes first |
| Filling an SSD to the brim | Pursuing 100% utilization | Keep 15-20% of SSD space free to maintain performance; only suggest cleanup when below 20% |
Permissions and supporting tools
- Some system files require administrator privileges (right-click "Run as administrator")
- Can be used together with built-in system tools:
cleanmgr, Storage Sense, DISM component cleanup - In-depth junk file locations, cleanup commands, and safety practices:
references/windows_cleanup_guide.md
Script Description
| Script | Function | Safety Features |
|---|---|---|
scripts/analyze_disk.py |
Directory usage ranking + large file list | Read-only; automatically skips directories without permission |
scripts/find_large_files.py |
Find files by size/type | Read-only; displays access time to assist judgment |
scripts/clean_temp.py |
Clean up temporary files/caches/logs/recycle bin | Simulated by default; --execute requires secondary confirmation; skips critical system directories |