Yzöwl Posted May 2, 2005 Posted May 2, 2005 (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 alsofor /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 May 2, 2005 by Yzöwl
staples Posted May 4, 2005 Posted May 4, 2005 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
Yzöwl Posted May 4, 2005 Posted May 4, 2005 @ staplesWhilst 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 fileAnother 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 offfor /d %%g in (%temp%\*) do rd /s/q "%%g"del /f/q/a %temp%\*.*goto :eof
jehuu_za Posted May 4, 2005 Author Posted May 4, 2005 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now