
- by x32x01 ||
Tired of your PC slowing down because temp folders fill up? You can make a simple one-click cleaner that removes temporary files from your user temp folder.
Below I give a ready-to-use .bat file (works instantly), a safer PowerShell alternative (lets you delete files older than N days), and instructions to schedule it or create a desktop shortcut so you run the cleanup with a double-click.
Important: deleting temp files is usually safe, but some apps may keep files open or use temporary files while running. Always save work and close apps before running cleaners.
What the script does (quick overview)
One-click BAT file (fast & simple)
Create a new text file, paste the code below, save it as clear-temp.bat, and double-click to run. It deletes the contents of your current user temp folder.
Safer PowerShell alternative (recommended)
This PowerShell script deletes files older than 7 days from your user temp folder and logs what it removed. It’s safer because it avoids removing recently used temp files and gives you control over the age threshold.
Save as
Create a desktop shortcut that runs elevated (double-click)
If your script needs admin rights for C:\Windows\Temp, create a shortcut that runs as administrator:
Schedule automatic cleanup with Task Scheduler
Tips & safety warnings
When NOT to use these scripts
Conclusion - quick, safe cleanup for everyday speed
A simple .bat gives you true one-click cleanup, while the PowerShell version offers safer, age-based deletion and logging. Combine a scheduled task with the PowerShell approach for low-maintenance cleanup that won’t remove recently used temp files.
If you want, I can:

Below I give a ready-to-use .bat file (works instantly), a safer PowerShell alternative (lets you delete files older than N days), and instructions to schedule it or create a desktop shortcut so you run the cleanup with a double-click.

What the script does (quick overview)
- Removes files and folders inside your current user Temp folder (
%TEMP%
) - usuallyC:\Users\<you>\AppData\Local\Temp
. - Optionally you can also clean
C:\Windows\Temp
(requires admin). - Handles most temp files but won’t remove files locked by running programs.
- You can run it on demand or schedule it to run automatically.
One-click BAT file (fast & simple)
Create a new text file, paste the code below, save it as clear-temp.bat, and double-click to run. It deletes the contents of your current user temp folder. Bash:
@echo off
title Clear Temp Files - Quick Cleaner
echo Closing… please save your work before continuing.
timeout /t 3 /nobreak >nul
echo Cleaning user temp folder: %TEMP%
cd /D %TEMP% 2>nul
echo Removing folders...
for /d %%D in (*) do rd /s /q "%%D" 2>nul
echo Removing files...
del /f /q * 2>nul
REM Optional: clean Windows Temp (uncomment next block if you want admin-level cleanup)
:: echo Cleaning C:\Windows\Temp (requires admin)
:: pushd C:\Windows\Temp
:: for /d %%D in (*) do rd /s /q "%%D" 2>nul
:: del /f /q * 2>nul
:: popd
echo Done!
pause
How to use
- Save the file as
clear-temp.bat
. - Double-click to run.
- The script will pause at the end so you can read the summary.
Safer PowerShell alternative (recommended)
This PowerShell script deletes files older than 7 days from your user temp folder and logs what it removed. It’s safer because it avoids removing recently used temp files and gives you control over the age threshold.Save as
Clear-Temp-Old.ps1
and run with PowerShell (see how to run below). Bash:
# Clear-Temp-Old.ps1 - delete temp files older than N days
param(
[int]$DaysOld = 7,
[switch]$IncludeWindowsTemp
)
$now = Get-Date
$paths = @($env:TEMP)
if ($IncludeWindowsTemp) { $paths += 'C:\Windows\Temp' }
$logFile = "$env:USERPROFILE\clear-temp-log-$(Get-Date -Format yyyyMMdd-HHmmss).txt"
"Cleaning temp folders - started at $now`r`n" | Out-File $logFile
foreach ($p in $paths) {
if (-Not (Test-Path $p)) { "Path not found: $p" | Out-File $logFile -Append; continue }
"Scanning $p" | Out-File $logFile -Append
Get-ChildItem -Path $p -Recurse -Force -ErrorAction SilentlyContinue |
Where-Object { -not $_.PSIsContainer -and $_.LastWriteTime -lt $now.AddDays(-$DaysOld) } |
ForEach-Object {
try {
Remove-Item $_.FullName -Force -ErrorAction Stop
"Removed file: $($_.FullName)" | Out-File $logFile -Append
} catch {
"Failed to remove: $($_.FullName) - $($_.Exception.Message)" | Out-File $logFile -Append
}
}
}
"Cleaning finished at $(Get-Date)" | Out-File $logFile -Append
Write-Host "Done. Log saved to $logFile"
Run the PowerShell script
- Right-click the script → Run with PowerShell (or open PowerShell and run:
.\Clear-Temp-Old.ps1 -DaysOld 7
). - To include
C:\Windows\Temp
, add-IncludeWindowsTemp
(requires elevated PowerShell).
Create a desktop shortcut that runs elevated (double-click)
If your script needs admin rights for C:\Windows\Temp, create a shortcut that runs as administrator:- Right-click desktop → New → Shortcut.
- For a BAT file:
C:\Windows\System32\cmd.exe /c "C:\path\to\clear-temp.bat
"
For a PowerShell script:powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\path\to\Clear-Temp-Old.ps1
" - After creating the shortcut, right-click it → Properties → Advanced → check Run as administrator.
- Now double-click the shortcut; Windows will prompt for consent (UAC), then run elevated.
Schedule automatic cleanup with Task Scheduler
- Open Task Scheduler (type it in Start).
- Create Task → give it a name like “Clear Temp Weekly”.
- Under Triggers → New → set schedule (daily/weekly).
- Under Actions → New → Program/script:
powershell.exe
Add arguments:-NoProfile -ExecutionPolicy Bypass -File "C:\path\to\Clear-Temp-Old.ps1" -DaysOld 7
- Under General → check Run whether user is logged on or not and Run with highest privileges if cleaning Windows Temp.
- Save - the script will run automatically per schedule.
Tips & safety warnings
- Close programs first. Close browsers and heavy apps (Office, editors) before cleaning to avoid deleting in-use temp files.
- Don’t delete temp files while installing software - installers use temp files.
- Locked files won’t delete - the script will skip files locked by running apps.
- Backups: for important data, always keep backups. Temp cleanup is maintenance, not a backup solution.
- Antivirus: some security products may flag or block unknown scripts - sign or whitelist scripts you trust.
- Test first: run PowerShell with -WhatIf patterns when experimenting (not used in examples above, but available for safer testing).
When NOT to use these scripts
- You need to preserve a temporary installer or a crash report you haven’t reviewed.
- You’re on a shared, managed PC with corporate policies - check with IT.
- You’re unsure where
%TEMP%
points on a particular account - inspect it first (echo %TEMP%
).
Conclusion - quick, safe cleanup for everyday speed
A simple .bat gives you true one-click cleanup, while the PowerShell version offers safer, age-based deletion and logging. Combine a scheduled task with the PowerShell approach for low-maintenance cleanup that won’t remove recently used temp files.If you want, I can:
- Provide a signed/packaged version to avoid AV alerts,
- Make a GUI wrapper (Windows) that runs the PowerShell cleanup with buttons and scheduling, or
- Produce a version that moves files to an archive folder instead of permanently deleting them.

Last edited: