How to Automatically Clean the Windows Temp Folder During Boot

Google Docs

A lot of space can be saved on your hard drive by clearing the Temp file, and here’s how safely delete the temp files from the previous day 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 the 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.


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 are 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.



  1. Ziggy

    September 24, 2014 at 7:26 pm

    Very nice, Brian. Like it!

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


    • Ziggy

      September 25, 2014 at 7:33 pm

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

  2. Cho

    September 25, 2014 at 10:37 am

    trying it …… hope nothing breaks….

  3. wcrewson

    September 25, 2014 at 10:48 am

    Hi used the tip for cleaning temp worked Perfectly, Thanks

  4. wheelsey_4

    September 28, 2014 at 5:58 pm

    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?

    • Brian Burgess

      September 29, 2014 at 3:49 pm

      @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

        September 29, 2014 at 6:25 pm

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

    • Swaroop

      May 27, 2021 at 5:52 pm

      I had this resolved. Before you shutdown your PC, please ensure all open files or folders are closed.

      Most of the people perform with files and folders still in open position. This prevents the corresponding temp.files from deleting them.

  5. DZinCA

    December 13, 2014 at 4:37 pm

    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!

  6. dagan

    March 29, 2015 at 11:32 am

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

    • Jeff Dunlop

      April 11, 2015 at 6:04 pm

      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

    April 11, 2015 at 6:03 pm

    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. Brian Q

    October 27, 2015 at 4:25 pm

    Great help! Thanks for sharing!

  9. Venu

    November 24, 2015 at 3:55 am


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

  10. H

    January 2, 2016 at 5:19 am

    What in case of Windows XP?

  11. AK

    February 11, 2016 at 9:00 am

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


  12. wheelsey_4

    May 31, 2016 at 7:40 pm

    Can I, now, delete that file?

  13. Ahmed Alaa

    August 6, 2016 at 2:39 pm

    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

    October 10, 2016 at 7:01 pm

    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

    October 19, 2016 at 2:18 pm

    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

    December 25, 2016 at 11:27 pm

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

  17. egresor

    March 1, 2017 at 4:23 pm

    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

    March 1, 2017 at 8:45 pm

    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!

    • Swaroop

      May 27, 2021 at 5:54 pm

      Keeping temp.files for 30 days is not a recommended practice unfortunately.

  19. Cagdas

    June 2, 2022 at 11:18 pm

    Hello Brian, i have a question about that.

    i do this press Windows+R
    write “temp” Press Enter there is files from: C:\Windows\Temp
    write “%temp%” Press Enter there is files from: C:\Users\username\AppData\Local\Temp

    is it possible to make this code for two of them ? Thanks in advance.

Leave a Reply

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


To Top