Jump to content

Clean up Temp Directory Automatically in Windows 10


Jordan

Recommended Posts

Clean up Temp Directory Automatically in Windows 10

 

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):

 

Windows 10 file explorer address bar temp

 

Windows 10 temp dir opened

 

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

This will remove the contents of the Temp directory in Windows 10.

Create clean temp batch file

 

Press Win + R shortcut keys together on the keyboard to open the Run dialog. Type or paste the following in the Run box:

shell:Startup

The text above is a special shell command which makes File Explorer to open the Startup folder directly.

 

Shell startup in the run box

 

Windows 10 startup folder opened

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 (or using any third-party program).

 

SOURCE

Link to comment
Share on other sites


  • Replies 5
  • Views 2.2k
  • Created
  • Last Reply
  • I do not think, that it would be a good idea to empty the folder, what Windows always deletes when done reboot or simply exit.
  • Why make empty only one Temp folder, if them are a lot more there and there are those, that Windows does not empty itself never.

It is not recommended to use Start folder for all users, but the current user start folder. But Windows do not like it also. Much wiser to use the registery key, ie, programs that must run for all users and always:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
or programs that start when current user is logged on
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Even nearly all antivirus and antimalware programs deletes everything what is in start folders, because Windows itselft don't use these folder nomore and usually only malware programs uses it.

But there is another thing, namely, beginning from the current Windows 10 version is not very easy to add programs there, I mean in registry. Windows has blocked it for users and also some installers cannot to do it no more. But it doesn't mean, that at all isn't possible. Of course it is possible, but not for everyone.

Link to comment
Share on other sites


5 hours ago, jordan4x said:

 

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.

 

 

The environment variable %temp% or %tmp% is there from Windows Vista times  . . So Its not a Windows 10-specific guide/procedure , this procedure is applicable to Windows Vista/7/8/8.1/10 - Not just Win 10

Link to comment
Share on other sites


5 hours ago, Kalju said:

I do not think, that it would be a good idea to empty the folder, what Windows always deletes when done reboot or simply exit.

 

Windows doesn't empty the temp folder in any version.  It was never designed to do so.  The original concept was that programs would store their data in the temp folder and delete it when you exited the program.  But anyone who has been around windows for any length of time in a tech capacity knows that has never happened consistently, not even with Microsoft programs.  Thus the need to clean it manually or with a 3d party program such as Ccleaner.  Starting with Windows 3.1 it was advisable to create a 'TMP' directory since some programs at the time looked for that directory instead of a 'TEMP' directory.  Once the environmental variables were programmed to point tmp to temp there was no longer a need to create a separate TMP folder.

 

38 minutes ago, NaJeEb303 said:

The environment variable %temp% or %tmp% is there from Windows Vista times  . . So Its not a Windows 10-specific guide/procedure , this procedure is applicable to Windows Vista/7/8/8.1/10 - Not just Win 10

 

Actually the environment variable has been present since Windows XP and was introduced in Windows NT.

Link to comment
Share on other sites


15 minutes ago, straycat19 said:

Actually the environment variable has been present since Windows XP and was introduced in Windows NT.

 

Yeah . , i know . , i'm talking about that specific environment variable (%temp% or %tmp%) . .

Link to comment
Share on other sites


Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...