At the edge of tweaking

Menu

Clear Temp Directory on Startup with Disk Cleanup

Recently, we saw how to clean up the temp directory automatically in Windows 10 using a simple batch file. In this article, we will see how to perform the same task using the built-in Disk Cleanup tool (cleanmgr.exe). Unlike the batch file, it shows a progress window with messages and a progress bar which gives you an idea of how long the operation will take.

As you may already know from the earlier article on how to "Clean up temp directory automatically in Windows 10", this is a special directory in Windows where the operating system stores temporary files. Temporary files are supposed to be deleted after the process which has created them has quit. However, this does not happen often. This causes the temporary directory to store them and grow in size filling your disk drive with files that you do not need.

You can check the current temp directory's contents using a special environment variable, %temp%(%tmp% also works). It points to the directory with temp files. Just type "%temp%" or "%tmp%" without quotes into the address bar of File Explorer:The Disk Cleanup app (Cleanmgr) is a built-in Windows tool which can remove various junk files to free up disk space. It can remove old Windows Update files, the browser cache, Recycle bin files and many other items all at once. One of its options is the ability to clean up the temporary directory. This is exactly what we need.

Disk Cleanup supports presets via a special pair of command line arguments, /SAGESET and /SAGERUN. You can create a preset to remove only the temp directory's contents and put a shortcut in your startup folder. So every time you sign in to your user account, the temp directory will be cleaned automatically. I suggest you to read the following articles before continuing:

About Sergey Tkachenko

Sergey Tkachenko is a software developer from Russia who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Facebook, Twitter or Google+.