April 29, 200521 yr 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
April 29, 200521 yr Hey I use this in my clean-up script:del "%systemdrive%\Documents and Settings\Administrator\Local Settings\Temp" /qrd "%systemdrive%\Documents and Settings\Administrator\Local Settings\Temp" /s /qdel "%systemdrive%\Documents and Settings\Administrator\Local Settings\Temporary Internet Files" /qrd "%systemdrive%\Documents and Settings\Administrator\Local Settings\Temporary Internet Files" /s /qdel "%userprofile%\Local Settings\Temp" /qrd "%userprofile%\Local Settings\Temp" /s /qmkdir "%userprofile%\Local Settings\Temp"del %systemdrive%\Recycled\?*.* /qrd %systemdrive%\Recycled /s/qdel %systemdrive%\Recycler\?*.* /qrd %systemdrive%\Recycler /s/qdel "%userprofile%\Local Settings\Temporary Internet Files" /qrd "%userprofile%\Local Settings\Temporary Internet Files" /s /qdefrag.exe %systemdrive% -fThe last line in this file also auto defrag's your PC Good luck!
April 29, 200521 yr Author 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??
April 29, 200521 yr What is the problem with deleting the folders? They will be recreated at the next logon!
April 29, 200521 yr This line will remove any of the directories in %temp%for /d %g in (%temp%\*) do rd /s /q %gThis line will remove the files in %temp%del /s /q /f %temp%\*.*Together in a batch@echo offfor /d %%g in (%temp%\*) do rd /s /q %%gdel /s /q /f %temp%\*.*goto :eof
April 29, 200521 yr This line will remove any of the directories in %temp%for /d %g in (%temp%\*) do rd /s /q %gThis line will remove the files in %temp%del /s /q /f %temp%\*.*Together in a batch@echo offfor /d %%g in (%temp%\*) do rd /s /q %%gdel /s /q /f %temp%\*.*goto :eof<{POST_SNAPBACK}>@Yzöwlhow to use this line :for /d %g in (%temp%\*) do rd /s /q %gif the path hase a space like this:for /d %g in (%windir%\Downloaded Installations\*) do rd /s /q %gor will it work like this if i dont use "edit:second questionif i want to keep the cookies in "Temporary Internet Files" and delete the resthow to do this in a batch file?edit2:if i use for /d %%g in (%temp%\*) do rd /s /q %%gthe system cant find the path
April 29, 200521 yr 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 noteI 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
April 30, 200521 yr Here A Vbs That Will Clean Out Your Temp Files On Error Resume NextDim ACTION : Set ACTION = CreateObject("WScript.Shell")RmTmp = ACTION.ExpandEnvironmentStrings("%UserProfile%\Local Settings\Temp") Fso.Deletefile (RmTmp & "\*.*") Fso.deleteFolder (RmTmp & "\*") Fso.deletefolder ( RmTmp & "\*.tmp")
April 30, 200521 yr 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 exampledel "%systemdrive%\Documents and Settings\Administrator\Local Settings\Temp" /qwould remove only the files which aren't read only /hidden etc. and none of the subdirectories or their contentsrd "%systemdrive%\Documents and Settings\Administrator\Local Settings\Temp" /s /qwould 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.
Create an account or sign in to comment