MSFN Forum: Empty %temp% -path, how? - MSFN Forum

Jump to content



Unattended CD/DVD Guide Homepage · MSFN Forum Rules

Welcome to the Applications Installs forum. Make sure you read the forum rules before you start posting.

Links/Requests to warez and/or any illegal material (porn, cracks, serials, etc..) will not be tolerated. Discussion of circumventing WGA/activation/timebombs/keygens or any other illegal activity will also not be tolerated.

We try our best to keep this forum clean of illegal content. If you see any illegal activity use the "report" button you find in every post to report the specific post to the moderators. If you ignore any of the rules you will be banned without notice.

Read Forum Rules
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Empty %temp% -path, how? How can I empty %temp% path? Rate Topic: -----

#1 User is offline   jehuu_za 

  • Group: Members
  • Posts: 8
  • Joined: 01-March 05

Posted 28 April 2005 - 11:57 PM

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


#2 User is offline   erik_demon 

  • Master Chief
  • PipPip
  • Group: Members
  • Posts: 253
  • Joined: 22-August 04

Posted 29 April 2005 - 01:03 AM

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!

#3 User is offline   jehuu_za 

  • Group: Members
  • Posts: 8
  • Joined: 01-March 05

Posted 29 April 2005 - 02:37 AM

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

#4 User is offline   rog 

  • Group: Members
  • Posts: 1
  • Joined: 20-October 04

Posted 29 April 2005 - 03:07 AM

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

#5 User is offline   jehuu_za 

  • Group: Members
  • Posts: 8
  • Joined: 01-March 05

Posted 29 April 2005 - 03:14 AM

Couse our s***ty SOE..

#6 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,117
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 29 April 2005 - 03:23 AM

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


#7 User is offline   jehuu_za 

  • Group: Members
  • Posts: 8
  • Joined: 01-March 05

Posted 29 April 2005 - 06:11 AM

Thanks..will try it monday..

#8 User is offline   sixpack 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 515
  • Joined: 29-May 04

Posted 29 April 2005 - 09:51 AM

Yzöwl, on Apr 29 2005, 10:23 AM, said:

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

<{POST_SNAPBACK}>

@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:

#9 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,117
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 29 April 2005 - 04:07 PM

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

#10 User is offline   sixpack 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 515
  • Joined: 29-May 04

Posted 30 April 2005 - 01:53 AM

got it all to work now, thanks for your time Yzöwl :)

#11 User is offline   gunsmokingman 

  • MSFN Addict
  • Group: Super Moderator
  • Posts: 1,991
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 30 April 2005 - 02:24 AM

Here A Vbs That Will Clean Out Your Temp Files

Quote

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


#12 User is offline   bledd 

  • msfn is a friend of mine!
  • Group: Supreme Sponsor
  • Posts: 1,732
  • Joined: 24-March 04

Posted 30 April 2005 - 08:52 AM

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

#13 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,117
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 30 April 2005 - 11:14 AM

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.

#14 User is offline   staples 

  • Junior
  • Pip
  • Group: Members
  • Posts: 61
  • Joined: 15-October 04

Posted 02 May 2005 - 05:52 AM

Over coded

rd %temp%\. /q/s

on windows 2k forward this works.

#15 User is offline   jehuu_za 

  • Group: Members
  • Posts: 8
  • Joined: 01-March 05

Posted 02 May 2005 - 09:02 AM

Quote

rd %temp%\. /q/s


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

#16 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,117
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 02 May 2005 - 09:09 AM

The code I gave was more a step by step, learning thing, especially with the @echo additions to prevent accidental deletions.

I do not know when the questioner actually Edited their post either, otherwise I would have added this also
for /f "tokens=*" %A in ('dir /b/s/a:d "%Temp%"') do @echo rd /s/q "%~A"
That will also remove all the directories within your temp folder, without removing the Temp itself

<Edit>
Yes you are correct jehuu_za that does delete the %Temp% directory too!
</Edit>

This post has been edited by Yzöwl: 02 May 2005 - 09:32 AM


#17 User is offline   staples 

  • Junior
  • Pip
  • Group: Members
  • Posts: 61
  • Joined: 15-October 04

Posted 03 May 2005 - 08:40 PM

Ok I found out "rd %temp%\. /q/s" on some windows xp it deletes %temp%.

to make it work you can fake it out by putting a log file in the location so the directory cannot be deleted.

Try this:

rd %temp%\. /q/s >%temp%\1.log

#18 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,117
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 04 May 2005 - 02:41 AM

@ staples
Whilst this is a very good idea, and one which would suffice in most cases, I still think it must be deleting and recreating the %Temp% directory. The reason I say this is that RD does not delete files, therefore the only way for those files to be deleted with that command is for the Temp directory to be removed and then remade for the log file to go inside. You would also of course now not have an empty Temp folder, meaning that in order to achieve the required result you would now have to issue a DEL command on the log file

Another method you could also use within your batch is pushd %Temp%, that'll put you inside the Temp folder, leaving it safe, then issue both the RD and DEL commands, (since as you can see from above, RD doesn't delete files), finally popd.

Incidentally, jehuu_za, why have you not commented on the method I originally gave as a working solution, or the vbs from gunsmokingman?
Here is a tidied version of my original response!
@echo off
for /d %%g in (%temp%\*) do rd /s/q "%%g"
del /f/q/a %temp%\*.*
goto :eof


#19 User is offline   jehuu_za 

  • Group: Members
  • Posts: 8
  • Joined: 01-March 05

Posted 04 May 2005 - 03:28 AM

Quote

Incidentally, jehuu_za, why have you not commented on the method I originally gave as a working solution, or the vbs from gunsmokingman?
Here is a tidied version of my original response!


Sorry..I forgot to test it ;) But now I have tested it and it works like a charm. Big thanks...I havent tested the .vbs couse the batch works fine.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy