Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empty %temp% -path, how?

Featured Replies

Hi.

My first post here :)

How can I delete all of the content in %temp% -path (using a dos batch file)without removing the temp path it self and mkdir it again?

I coud do it if I only knew what kind of directories it contain, but haven't managed to empty it with only one command.

Allready tried:

rmdir /S /Q %temp%\*

please help ;)


Hey :hello:

I use this in my clean-up script:

del "%systemdrive%\Documents and Settings\Administrator\Local Settings\Temp" /q
rd "%systemdrive%\Documents and Settings\Administrator\Local Settings\Temp" /s /q
del "%systemdrive%\Documents and Settings\Administrator\Local Settings\Temporary Internet Files" /q
rd "%systemdrive%\Documents and Settings\Administrator\Local Settings\Temporary Internet Files" /s /q
del "%userprofile%\Local Settings\Temp" /q
rd "%userprofile%\Local Settings\Temp" /s /q
mkdir "%userprofile%\Local Settings\Temp"
del %systemdrive%\Recycled\?*.* /q
rd %systemdrive%\Recycled /s/q
del %systemdrive%\Recycler\?*.* /q
rd %systemdrive%\Recycler /s/q
del "%userprofile%\Local Settings\Temporary Internet Files" /q
rd "%userprofile%\Local Settings\Temporary Internet Files" /s /q

defrag.exe %systemdrive% -f

The last line in this file also auto defrag's your PC :thumbup

Good luck!

  • Author

Like I said.. Without deleting/removing the actual %temp% -directory and remaking it.

If I use the "del /f /s /q %TEMP%\*" it only deletes the files, not directories.

And if I use "rd /s /q %temp%\" it deletes also the %temp% -directory and i"rd /s /q %temp%\*" doesn't work.

Can't I do it without some kind of FOR-loop?

EDIT: I coud do "dir /a:d /b > file.txt" in %temp% and then make somekind of FOR-loop for reading the names of the directories from that file and then remove them one by one. But there must be a easier way to do this! Is there??

What is the problem with deleting the folders? They will be recreated at the next logon!

This line will remove any of the directories in %temp%

for /d %g in (%temp%\*) do rd /s /q %g

This line will remove the files in %temp%

del /s /q /f %temp%\*.*

Together in a batch

@echo off
for /d %%g in (%temp%\*) do rd /s /q %%g
del /s /q /f %temp%\*.*
goto :eof

This line will remove any of the directories in %temp%
for /d %g in (%temp%\*) do rd /s /q %g

This line will remove the files in %temp%

del /s /q /f %temp%\*.*

Together in a batch

@echo off
for /d %%g in (%temp%\*) do rd /s /q %%g
del /s /q /f %temp%\*.*
goto :eof

@Yzöwl

how to use this line :

for /d %g in (%temp%\*) do rd /s /q %g

if the path hase a space like this:

for /d %g in (%windir%\Downloaded Installations\*) do rd /s /q %g

or will it work like this if i dont use "

edit:

second question

if i want to keep the cookies in "Temporary Internet Files" and delete the rest

how to do this in a batch file?

edit2:

if i use

for /d %%g in (%temp%\*) do rd /s /q %%g

the system cant find the path :blink:

After a short PM exchange with sixpack, I thought I had better explain something.

The single line commands I gave are not for use in a batch file. They are to be entered into a command prompt window. If you haven't set your command prompt options for, right click paste and /or tab completion, you can also enter them into the Start » Run box after first typing 'cmd /c '

Now if you wish to test the file for what will be deleted, instead of possibly removing directories you didn't mean to using the Start » Run box as above, you will want to keep the window open, to see your results. To do this type 'cmd /k ' first, instead of 'cmd /c '. All I have added to the commands below is '@echo ', when your through with testing remove that and revert to the 'cmd /c ' prefix.

cmd /k for /d %g in (%temp%\*) do @echo rd /s /q "%g"

cmd /k for /d %g in ("%windir%\Downloaded Installations\*") do @echo rd /s /q "%g"

I hope this helps!

Additional note

I have also added something which I had omitted in my earlier examples, the quotes around the %g at the end, this will be necessary for any directories with spaces anywhere in their path names

Here A Vbs That Will Clean Out Your Temp Files

On Error Resume Next

Dim ACTION : Set ACTION = CreateObject("WScript.Shell")

RmTmp = ACTION.ExpandEnvironmentStrings("%UserProfile%\Local Settings\Temp")

  Fso.Deletefile (RmTmp & "\*.*")

  Fso.deleteFolder (RmTmp & "\*")

  Fso.deletefolder ( RmTmp & "\*.tmp")

was about to post the list I created, but Erik Demon already has :)

That as the questioner has already stated removes the Temp directory, which was a non requirement.

It seems like it's longer than it needs to be, for example

del "%systemdrive%\Documents and Settings\Administrator\Local Settings\Temp" /q

would remove only the files which aren't read only /hidden etc. and none of the subdirectories or their contents

rd "%systemdrive%\Documents and Settings\Administrator\Local Settings\Temp" /s /q

would remove the temp directory plus all its files subdirectories and contents. Surely just the second command would have done it all!

Don't get me wrong I am not criticizing your coding, it's just a little overcoded.

  • Author
rd %temp%\. /q/s

Does remove the %temp% dir also, or did I use it wrong?

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.