Every Windows version uses a special directory which stores temporary files. These files are created by various Windows services, installed apps and tools. Temporary files can be safely deleted after the process which has created them has quit. However, this does not happen often, so the temporary directory continues to store them and fills your disk drive with junk. Here is how to clean up the temp directory automatically in Windows 10.
There is a special environment variable in Windows 10, %temp%, which points directly to the directory with your temp files. You can test it in action by typing %temp% in the address bar of the File Explorer (%tmp% also works):
Using this information, you can quickly create a batch file that will remove all the temp folder's content. If you put this batch file in your Startup folder, you'll get your Temp folder cleaned every time your start your PC.
Before you proceed, I suggest you to apply the following tweak: Add Batch file (*.bat) to New menu of File Explorer. You can save a lot of time by having the ability to create a new batch file directly.
Clean up temp directory automatically in Windows 10
- Create a new batch file with the following content:
@echo off del "%tmp%\*.*" /s /q /f FOR /d %%p IN ("%tmp%\*.*") DO rmdir "%%p" /s /q
- Press Win + R shortcut keys together on the keyboard to open the Run dialog. Type or paste the following in the Run box:
The text above is a special shell command which makes File Explorer to open the Startup folder directly.
- Move your batch file to the Startup folder and you are done!
Note: We intentionally did not delete the %temp% folder itself using batch commands because deleting the folder and recreating it can cause various permissions issues with the hundreds of apps that write to it. It is safer to delete the files inside it first and then the empty folders.
After doing the steps above, you can reboot your PC and open your Temp folder. You will find lesser files there than before. This will save you disk space and your time, since you need not clean the folder manually.