以下是一个Windows批处理脚本,用于清理常见的系统垃圾文件:
@echo off
echo 正在清理系统垃圾文件...
del /f /s /q %systemdrive%\*.tmp
del /f /s /q %systemdrive%\*._mp
del /f /s /q %systemdrive%\*.log
del /f /s /q %systemdrive%\*.gid
del /f /s /q %systemdrive%\*.chk
del /f /s /q %systemdrive%\*.old
del /f /s /q %windir%\prefetch\*.*
rd /s /q %windir%\temp & md %windir%\temp
del /f /q %userprofile%\recent\*.*
del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\*.*"
del /f /s /q "%userprofile%\Local Settings\Temp\*.*"
del /f /s /q "%userprofile%\recent\*.*"
echo 正在清理回收站...
rd /s /q C:\$Recycle.bin
echo 系统垃圾清理完成
pause
PowerShell系统清理脚本
对于更高级的清理功能,可以使用PowerShell脚本:
# 清理临时文件
Remove-Item -Path "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "$env:SystemRoot\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
# 清理下载的程序文件
Remove-Item -Path "$env:SystemRoot\Downloaded Program Files\*" -Recurse -Force -ErrorAction SilentlyContinue
# 清理Windows错误报告
Remove-Item -Path "$env:SystemRoot\System32\winevt\Logs\*" -Recurse -Force -ErrorAction SilentlyContinue
# 清理缩略图缓存
Remove-Item -Path "$env:LocalAppData\Microsoft\Windows\Explorer\thumbcache_*.db" -Force -ErrorAction SilentlyContinue
# 清空回收站
Clear-RecycleBin -Force -Confirm:$false
注意事项
执行脚本前建议先备份重要数据
以管理员身份运行脚本可获得最佳清理效果
某些系统文件可能需要重启后才能被删除
定期运行可保持系统清洁,建议每周执行一次