Deleting Temporary Files with a Batch File and Running it Silently with Windows Scheduler

Опубликовано: 04 Август 2026
на канале: Analyst Ninja
248
4

how to delete temporary files, %temp% files, prefect files, recent files, and clean the Recycle Bin using a batch file. We'll also set up a task in Windows Scheduler to run this batch file every hour silently, without any pop-ups.

Below are require code to do the task,

Batch File code

@echo off
echo Deleting temporary files...
del /s /q %temp%\*
del /s /q C:\Windows\Temp\*
echo Deleting prefetch files...
del /s /q C:\Windows\Prefetch\*
echo Deleting recent files...
del /s /q %userprofile%\Recent\*
echo Cleaning Recycle Bin...
PowerShell -NoProfile -Command Clear-RecycleBin -Confirm:$false
echo Done!


VBS Script code

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\path\to\temp_clean.bat" & Chr(34), 0
Set WshShell = Nothing

Make sure to replace C:\path\to\temp_clean.bat with the actual path to your batch file."