tmp folder in Windows like /tmp in Linux

Diego Herranz picture Diego Herranz · Feb 27, 2013 · Viewed 15.5k times · Source

I have created a folder in Windows, C:\tmp\ and I want it to behave like /tmp/ folder in Linux, i.e. its contents are removed every time the system is booted.

I think the commands to run could be (at least on windows 7):

RD C:\tmp /S /Q
MKDIR C:\tmp

A way to execute this commands on every boot? Or, any better way to accomplish this?

Answer

Jens Erat picture Jens Erat · Feb 27, 2013

You should use the environment variable %TEMP% which points to different locations on different Windows versions, but is the defined location for temporary data in Windows.

Windows doesn't clean it up by itself, but it is fine to delete its contents on shutdown (and as lots of applications don't clean up properly, it is recommended to do so once in a while).

Do not delete the %TEMP% folder, but it's contents using del %TEMP%\* /s /f /q which will delete the contents instead, so you don't need to recreate the folder.

For setting up a shutdown-script, use the answer provided by @Alex K.