Jump to content

Empty %temp% -path, how?


jehuu_za

Recommended Posts

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

Link to comment
Share on other sites


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!

Link to comment
Share on other sites

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??

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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