Bat file to delete temp files.
1 06 Oct 2017 00:05 by u/toobaditworks
This may help someone who wants to be able to delete a bunch of files with a click of a button or on schedule.
I was wanting to delete temp files like cookies and others that weren't getting deleted. I started off going into the directories and making favorites of the folders and then manually going into them and deleting the files. After a while I kept adding new folders to this and it got to be a pain having to go into so many folders. So I made this batch file to do it.
This works on win7 I don't know if it works on others. It will delete the files and folders in the directories. You can add other directories to it to suit your needs.
Step 1: Make a new text file and change the name to DeleteTemp.bat (call it whever you want but make sure it has .bat)
Step 2: Add the following lines to it.
@ECHO OFF
rmdir /s /q %temp%
del /f /s /q %LocalAppData%\Temp*.*
del /f /s /q %userprofile%\AppData\Local\Temp*
forfiles /P %userprofile%\AppData\Local\Temp\ /C "cmd /c if @isdir==TRUE rmdir /S /Q @file"
takeown /R /F /S "%AppData%\Microsoft\Windows\Cookies\Low"
del /f /s /q%AppData%\Microsoft\Windows\Cookies\Low*.*
takeown /R /F /S "%userprofile%\AppData\Local\Temporary Internet Files"
del /f /s /q "%userprofile%\AppData\Local\Temporary Internet Files*"
forfiles /P "%userprofile%\AppData\Local\Temporary Internet Files*" /C "cmd /c if @isdir==TRUE rmdir /S /Q @file"
cmd /k
Step 3: Save the file.
Step 4: Run it.
1 comment
0 u/toobaditworks [OP] 06 Oct 2017 01:33
Another example is you can use SET command to set the directory then use this to delete the files in the folder you choose. Remove the rmdir line if you DON'T wish to delete the entire directory afterwords. And be careful with this.