A batch file to delete temp user files

August 2017

A Windows batch file is a type of text file, which contains a series of commands for a computer's operating system. You should not open batch files on your hard disk that are unknown as they contain executable commands. The file extension for batch file is .BAT. The Temp files (Temporary files) are created by system programs essentially when the programs cannot get the appropriate level of memory to complete a task. Using batch files you can view, access and erase the content of the temporary files as you would do in the Command prompt by typing a specific set of commands.


I'm trying to create a batch file to clean my business PC (such as the contents of Temp files and Temporary Internet Files for each user...)


This script deletes all files in
  • C:\Documents And Settings\<UserName>\Local settings\Temp and
  • C:\Documents And Settings\<UserName>\Local settings\Temporary Internet Files

@echo off   
cd /d %temp%   
for /r %%a in (*.*) do (   
del /f /q %~a   
) >nul   
cd /d "%UserProfile%\Local Settings\Temporary Internet Files   
for /r %%b in (*.*) do (   
del /f /q %~b   
) >nul   

Thanks to theo7777 for this tip.


Published by deri58. Latest update on March 11, 2012 at 04:22 PM by Virginia Parsons.
This document, titled "A batch file to delete temp user files," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).