Jump to content

Recommended Posts

Posted (edited)

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>

Edited by Yzöwl

Posted

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

Posted

@ 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

Posted
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.

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