How-To

Windows Tip: Automatically Clean the Temp Folder During Boot

Windows always has temp files and other junk that’s just taking up space on your hard drive. We’ve covered several ways to clean up the extra junk by using Disk Cleanup to using third-party utilities like CCleaner.

For more, check out our article: Five Ways to Reclaim Windows Disk Space.

Most of the methods in that article end up cleaning out the Temp folder, but you might want to keep that folder as clean as possible. Here’s how to create a bat file that will allow you to clean out the Temp file each time you boot up.

Windows Temp File

First, let’s take a look at the Temp folder in Windows. To get to it in Windows 7 type: %temp% in search field in the Start menu, or on Windows 8.1, hit the Windows Key and type the same thing from the Start menu and hit Enter.

temp

That opens the Temp folder, and if you want to clean it out manually, just hit Ctrl + A to  select everything in it, and then Delete. Not all of the files and folders will be deleted though as those files are currently in use.

In fact, you really don’t want to delete any temp files that were created since you booted up the PC for performance sake.

Windows Temp Folder

Create a Batch File to Automatically Clean Temp Folder

A lot of space can end up being saved on your hard drive by clearing out the Temp file. And if you shut down your PC every night, you can safely delete the temp files from the previous day during boot.

Open Notepad and type in the following:

rd %temp% /s /q

md %temp%

Now, save the file exactly as the path below:

%appdata%\microsoft\windows\start menu\programs\startup\cleantemp.bat

That will create your batch file and save it inside the Startup folder.

bat file

After creating the batch file, I rebooted my PC and opened the Temp folder, you can see there’s far fewer files in it compared to the image above.

after reboot

While Windows 8.x doesn’t have a Start menu, it has the Startup folder – here’s how to find it. So the cool thing is that the instructions above will work in both versions.


22 Comments

22 Comments

  1. Very nice, Brian. Like it!

    Here’s another great free tool to clean junk from one’s computer: AFT Cleaner…

    Link: http://www.softpedia.com/get/Security/Secure-cleaning/ATF-Cleaner.shtml

    • Oops! My comment should read ATF Cleaner NOT AFT Cleaner. Apologies…

  2. Cho  

    trying it …… hope nothing breaks….

  3. wcrewson  

    Hi used the tip for cleaning temp worked Perfectly, Thanks

  4. wheelsey_4  

    Brian, after my laptop restarted, a command prompt showed up saying that file could not be used for some reason I did not have time to copy before it closed on its own. Any suggestions?

    • @wheelsey_4: When the process runs during startup to clean out the temp file, a command prompt will display briefly then go away.

      If you’re getting an error message, I am thinking it might be because it’s telling you a certain file cannot be deleted due to a program needing it?

      I guess I don’t know for sure unless you can get the exact error.

      • wheelsey_4  

        Thanks, yeah, it worked. It cleaned out a crap load of stuff. Thanks

  5. DZinCA  

    Hello Brian,
    Thank you very much. This helps a lot. I was getting sick of constantly going to the folder to empty the files.

    I have a related question. Would you kindly let me if there are bat files to empty the windows’ temp folder? That too gets filled, as well the “windows\softwareDistribution\download”?

    Many thanks again and Merry Christmas!
    Cheers,
    D

  6. dagan  

    how does one UNDO this? – -I can’t install a certain program because of it

    • Jeff Dunlop  

      You can’t undo this unless you have backups of your temp folder which I would never do. I’d bring up your issue with the program that’s using your temp folder as an appdata folder.

  7. Jeff Dunlop  

    Nice tip. I’ve been doing this manually for ages and this greatly simplifies things. It’s annoying that programs use the temp folder as a garbage dump when by definition if the process exits normally it should clean up its crap.

  8. Great help! Thanks for sharing!

  9. Venu  

    Hello

    thank for the tip and..can we delete some of other cache folders which created by visual studio..

  10. H  

    What in case of Windows XP?

  11. AK  

    Is it a one time batch or you need to run it whenever you want to clear your temp files automatically.
    Awaiting your response.

    Regards,
    Ahmed

  12. wheelsey_4  

    Can I, now, delete that file?

  13. its very simple to remove all temp files in windows 7 64bit or 32bit, just do the below :
    1- open (RUN) and write %temp% then ENTER.
    2- you will find that all temp files in that folder, just remove what you want.

    Thank You

  14. thatdudejbob  

    Thank you very much for this tutorial.
    It was very easy to follow and works perfectly.

    To anyone looking to do this, I highly recommend it.
    You will not have any regrets in the matter.

  15. Ikay  

    Thanks for this..but how do I stop the command from loading everytime I boot. It takes time before I’m able to use my laptop after booting.

  16. Idris  

    Hello Brian, I get “path does not exist, check the path and try again” when trying to save the file

  17. egresor  

    I also had temp folders that would not delete. I tried bc wipe and other methods…all to no avail.

    I think it was 7zip related. I had the same folder on my desktop and it would not delete. Found a post about it might be 7zip related. 7zip delete did get rid of it, but the empty temp folders were not touched. Trying 7zip would not delete them.

    The batch file worked great. Thanks!

  18. WranglerRouser  

    You mention that this will create a bat file that will clean out the Temp file each time I boot up. I would like to instead create a bat file that will clean out contents in the Temp file only after they have been there for 30 days. Is that possible and how would it be done? Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

 

To Top