Can I Delete Temporary Files in Windows?

Why are so many left undeleted?

Temp files can pile up. Why is that, and do you need to worry about them?

Question: Why are there so many temporary files left behind each time the computer is shut down and restarted?

There are indeed many temporary files. As I write this, my primary machine has 322 files in its temporary folder that total 58 megabytes. My example PC, which isn’t used nearly as heavily, has 134 files taking up 78 megabytes.

Just as there are many files, there are also many reasons they get left behind.

TL;DR:

Temporary files in Windows

Temporary files accumulate due to crashes, improper shutdowns, running programs, updates, caching, logging, and sometimes just poor programming. While they’re supposed to be deleted automatically, some scenarios leave them behind. Tools like Windows Disk Cleanup or Storage Sense can help remove them.

Why temporary files?

A temporary file is, as the name implies, a file on your hard disk that is created by software and is intended to be temporary. When the program finishes using the temporary file, it deletes it. You’re never supposed to see it.

Programs use temporary files for a variety of reasons, including:

  • A need to operate on more data than is practical to keep in RAM.
  • Data that preserves the state of software over time.
  • Data that might be used to implement features like “undo” and “redo” in applications.
  • Logs, transaction logs, journals1, internally managed caches, and more.
  • …whatever else the program designer wanted them for.

The reasons are as varied as the programs are.

As I said, the intent is for temporary files to be cleaned up at some point.

The reason we’re here is that despite those good intentions, that doesn’t always happen.

Viewing temporary files

The easiest way to view your temporary files is to enter “%TMP%” in Windows File Explorer’s address bar.

%TMP% in Windows File Explorer
Type %TMP% in Windows File Explorer. (Screenshot: askleo.com)

This opens the temporary folder for your login account. (Each account has its own, as does the system itself, at C:\Windows\Temp.)

The contents of my Temp folder.
The contents of my Temp folder. Click for larger image. (Screenshot: askleo.com)

You can see that my temp folder is located in C:\Users\lnote\AppData\Local\Temp. It has 382(!) items in it, consisting of many oddly named folders and files.

Let’s look at some of the reasons they may have been left behind.

Crashes

This is probably what comes to mind first for most folks. If a program that uses temporary files crashes, it doesn’t have a chance to delete the temporary files it was using. Some programs are written to clean up previously existing temporary files the next time it runs, but I’d say most do not.

And of course, Windows is a program that uses temporary files. If Windows crashes, it won’t have an opportunity to clean up.

Shutdown

An improper shutdown can leave temporary files behind. If you’ve ever had to long-press the power button to shut down Windows, that behaves much like a crash. Whatever temporary files are in use at the time remain. A “normal” shutdown — using either Shutdown or Restart — gives the operating system a chance to clean up on the way out.

Running programs

Of course, if a program is currently running and it uses temporary files, you’ll find those. There’s a lot of software running on your machine from the moment you fire it up to the moment you shut it down. Much of that software, such as services and background applications, you never see.

Updates and rollback

Windows and other software updates may leave behind temp files to assist with installation or rollback. Particularly for rollback, those temp files will be left behind. The side effect of deleting those temp files might be the inability to roll back an update.

Caches

I have a couple of programs on my machine that, the first time you run them, perform one-time configurations or even lengthy calculations. Those calculations are preserved for subsequent runs. Sometimes the results of configurations are saved as temporary files. Deleting those temporary files forces the program to repeat its initialization the next time it’s run.

Logging

Some programs make a log of particular actions or other activities as they do their job. By not deleting those logs, they remain available for analysis during troubleshooting.

Bad programming

This has to be mentioned, as it’s probably the second reason most people think of when looking at long lists of temp files. There are two ways poor programming increases the number of temp files.

  • Using the system’s temporary file location when an app-specific location might be more appropriate. In the caching example above, for instance, the application should be keeping its cached information in its own folders to more properly manage those files. Putting them in the system temp folder means they may get unexpectedly deleted or, in severe cases, damaged by other programs.
  • Just bad code. Sometimes software is written to create temporary files without thinking through all the scenarios in which they should be cleaned up.

Another way to view and clean up temp files

Search the Settings app for “storage”. On the resulting page, click on the line for Temporary Files.

Temporary Files in Settings.
Viewing temporary files in settings. Click for larger image. (Screenshot: askleo.com)

This will present the categories of temporary files currently on your machine, along with descriptions and the option to delete some or all of them.

Do this

For the most part, temporary files are not something you need to worry about often. If you do, tools like Storage Sense (or Windows Disk Cleanup) give you a quick and easy way to clean ’em up.

Subscribe to Confident Computing! Less frustration and more confidence, solutions, answers, and tips in your inbox every week.

Podcast audio

Play

Footnotes & References

1: These aren’t typically human-readable logs, but logs used by the application to maintain, repair, and analyze other data structures.

15 comments on “Can I Delete Temporary Files in Windows?”

  1. From my experience, I’d say bad programming is the main cause of temporary files on my machine. Even when I haven’t exited a program via Task Manager or had any of the other scenarios mentioned in the article, I get dozens of temp files in the %temp% folder and other locations. I run Disk Cleanup a couple of times a week, especially on my laptop with a small 500 GB drive.

    Reply
  2. I delete temp files when I run a weekly scan. Both free utilities that I use offer that option before starting the scan.

    Are they really clearing them all, or is that an illusion and I should be using a method detailed in this article?

    Reply
  3. Who needs a utility? We routinely delete temporary files from c:\Temp nightly using the great file manager Directory Opus (but you could use Windows Explorer or any other file manager that you fancy). For decades, I’ve set up our computers to place all temporary files in c:\Temp. At the end of the day, we just open that directory (now I’m really giving away my age) in our file manager and select all the temp files and delete. The literal handful that cannot be deleted simply are not deleted. Then I just empty the recycle bin. Takes all of 10-20 seconds which I imagine anybody can spare. Then we shut down the computers for the night (we’ve got absolutely no reason on earth to leave them on overnight.)

    Reply
    • I cannot recommend CCleaner enough. It is actually a suite of very helpful utilities that will locate dup’s and even analyze photos for blurry or out-of-focus pics… Available for Mac and PC. (I have no connection to the publisher, just like to recommend good software).

      Reply
    • CCLeaner is good for deleting many temporary files, but IIRL, Leo has a video about things like the registry fixers and other tools CCLeaner includes (It’s gone way past focusing on what it could do back when it was named Crap Cleaner.) I think it’s good, but stick to the file cleaning part of it.

      Reply
  4. There are more locations than Leo mentioned. I’m not going to list them all because messing around in the locations they are may be dangerous, which may be why Leo left them out. (You have backups just in case, right? <- remember to check to see if you can restore something from them today. Make a calendar event to test restoring from them.)

    More limited computers with really small drives, like you'd find connecting to things like large touch screens or basically embedded devices, may make it worth it to dig around in these other locations. Unless you have even as little as 500MB free on your drive (maybe less), it's not worth it to go looking for them. Stick to well defined and trusted tools

    Remember that space is relatively cheap and temporary files don't slow down your computer (more than any other files can if your drive really gets full). 95% of computers don't need to worry about too many temporary files.

    Reply
  5. Leo…

    You mentioned the “%TMP%” variable, but isn’t there also a “%TEMP%” variable, as well? Do they both point to the dame directory?

    Reply
  6. I run a daily batch so it is convenient to add the following simple commands for temporary file size control:

    :Remove_AppData_Temp_Files_LAST_ACCESSed_More_Then_20-Days-ago
    SET _SRC=C:\Users\Eric\AppData\Local\Temp
    FORFILES /P %_SRC% /S /C “CMD /C DEL /Q @path” /D -20 > NUL 2>&1
    :Remove_empty_folders
    FOR /f “delims=” %%i in (‘DIR %_SRC% /AD /S /B ^| SORT /R’) DO RD “%%i” > NUL 2>&1

    :Remove_Windows_Temp_Files_LAST_ACCESSed_More_Then_20-Days-ago
    SET _SRC=C:\Windows\Temp
    FORFILES /P %_SRC% /S /C “CMD /C DEL /Q @path” /D -20 > NUL 2>&1
    :Remove_empty_folders
    FOR /f “delims=” %%i in (‘DIR %_SRC% /AD /S /B ^| SORT /R’) DO RD “%%i” > NUL 2>&1

    The first commands remove temp files accessed more than 20 days ago and the second any empty folders left behind.

    Also note Windows Defender log is a single temp file:
    C:\Users\xxx\AppData\Local\Temp\MpCmdRun.log

    Reply

Leave a reply:

Before commenting please:

  • Read the article.
  • Comment on the article.
  • No personal information.
  • No spam.

Comments violating those rules will be removed. Comments that don't add value will be removed, including off-topic or content-free comments, or comments that look even a little bit like spam. All comments containing links and certain keywords will be moderated before publication.

I want comments to be valuable for everyone, including those who come later and take the time to read.