14

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?

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
Diego Herranz
  • 2,857
  • 2
  • 19
  • 34

2 Answers2

7

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.

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
  • `del %TEMP%\* /s /f /q` deletes the contents and the contents inside the subfolders but not the subfolders themselves so I think I'll stick with the recreation of the folder. Thanks. – Diego Herranz Feb 27 '13 at 13:49
5

I do it via a shutdown script to clear a directory called c:\null

Run gpedit.msc & see http://technet.microsoft.com/en-us/library/cc770300.aspx for instructions on configuring a script to run.

The bat file I run is

@echo off
@rd c:\null\ /s /q
@md c:\null
Alex K.
  • 171,639
  • 30
  • 264
  • 288