tmp folder in Windows like /tmp in Linux [closed]
Asked Answered
P

2

15

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?

Professoriate answered 27/2, 2013 at 11:36 Comment(0)
B
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
Bridgid answered 27/2, 2013 at 11:40 Comment(3)
I've just realized that I have Windows 7 Home Premium and gpedit.msc is not available. Any workaround?Professoriate
There are logoff/on events you can use to run something via task scheduler (taskschd.msc)Bridgid
taskschd.msc did it. Thanks.Professoriate
M
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.

Marilla answered 27/2, 2013 at 11:55 Comment(1)
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.Professoriate
B
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
Bridgid answered 27/2, 2013 at 11:40 Comment(3)
I've just realized that I have Windows 7 Home Premium and gpedit.msc is not available. Any workaround?Professoriate
There are logoff/on events you can use to run something via task scheduler (taskschd.msc)Bridgid
taskschd.msc did it. Thanks.Professoriate

© 2022 - 2024 — McMap. All rights reserved.