User Tools

Site Tools



Clean Temp Directory

Any windows machine will fill up with temporary files, and many applications do not clean up after themselves very well. The following batch file will delete all files older than 30 days in your personal temp folder.

echo off
echo "Cleaning out Windows Temp folder"
forfiles /p %temp% /s /m *.* /D -30 /C "cmd /c echo @PATH" 2>nul || goto NoFiles
choice /m "Ready to delete these files? " /t 10 /d n
if ErrorLevel 2 goto No
if errorlevel 1 goto Yes
goto End
echo No files found
goto end
echo Aborted
goto End
forfiles /p %temp% /s /m *.* /D -30 /C "cmd /c del @PATH"
echo Files Deleted

Windows System Temp Folder

Windows has no way to easily clean up the c:\windows\temp directory. This keeps filling up and eventually, will take up a significant amount of disk space (25G on a machine that only acts as a QuickBooks server). It is recommended to remove files over a certain age occasionally.

You can remove any files in the Windows Temp folder (c:\windows\temp) older than 30 days with the following PowerShell command:

Get-ChildItem –Path  “C:\Windows\Temp” –Recurse | Where-Object{$_.CreationTime –lt (Get-Date).AddDays(-30)} | Remove-Item -WhatIf

the -WhatIf at the end of that command says “do a dry run”, ie show what would happen, but don't actually do it. Remove that in order to actually clean up the system (remove the files).

To run this, find PowerShell and open as Administrator, then type the command in. You could also automate it by having it set up as an At job, but you would need to go in and allow PowerShell scripts to be run on the system, which I did not include here.

microsoft_windows/cleantemp.txt · Last modified: 2019/01/08 17:36 by rodolico