May 2, 200521 yr 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, 200521 yr by Yzöwl
May 4, 200521 yr 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
May 4, 200521 yr @ 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
May 4, 200521 yr Author 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