OK, I've decided to get this ever stagnant thread with a simple script which many of you should be able to understand and use with ease:
Windows Temporary File Cleaner:
Actual commands are in bold
Conditional commands in green
parameters in blue.
Text with no effect other than being displayed as is, in red.
You could save the above script into a text file with an extension of either .bat or .cmd and it should run on Windows XP with no issues.@echo off
title Windows Temp File Cleaner
color 5f
echo.
echo.
echo Please Close All Programs Before You Continue!!
echo.
echo.
echo.
pause
cls
del /f /s /q "%userprofile%\Local Settings\Temp\*.*"
del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\*.*"
del /f /s /q "%userprofile%\Recent\*.*"
del /f /s /q "%userprofile%\Local Settings\History\*.*"
del /f /s /q "%userprofile%\Cookies\*.*"
del /f /s /q "%appdata%\Microsoft\Office\Recent\*.*"
del /f /s /q "%userprofile%\~*.*"
del /f /s /q "%WINDIR%\Prefetch\~*.*"
IF EXIST "%windir%\KB*.log" del /f /q "%windir%\KB*.log"
IF EXIST "%windir%\Q*.log" del /f /q "%windir%\Q*.log"
exit
Slight variations in the user shell file locations in Vista and 7 would make this script at least partially invalid/ineffective.
Now a quick rundown of the script starting with the first line:
Every script I create will have this as the first line to suppress the command that is being executed from appearing on the screen as an output (echoing)@echo off
Without the @echo off command, script output would include the current command in the output, making things confusing if not annoying at the very list. If you use on instead of off, that the commands would actually be echoed in the output.
does exactly what the name implies, title command followed by a single space display whatever text typed (after it) on the top bar of the command line window:title Windows Temp File Cleaner
Color command modifies the color of the background and the font based on 16-colors used in DOS environment.color 5f
First character indicates the background color and the second character is for the color of the font. If you open a Command Line window, simply typeand it will show you all available colors and the corresponding character for each one. 0 through 9 and A through F, totaling 16 colors total. The ones with letters are used for bright colors, some overlapping. For example, both number 7 and F are used for color white but the white you get with F is much brighter, crispier and easier to see in darker backgrounds, naturally.color /?
Experiment yourself with different color combination to see for yourself.
To make things, I have already went through and picked a bunch that I thought were suitable to be used in scripts:
If you use don't care for the lame Black/dull White used in Command Line by default, then change it by:=== Cool Color Combos ===
09 0A 0B 0C 0D 0E 0F
17 1C 1E 1F
20 27 2E 2F
30 37 3E 3F
40 47 4B 4E 4F
50 57 58 5B 5E 5F
60 61 67 69 6F
71 73 74 75 79 7C 7D
81 84 85 87 89 8A 8B 8E 8F
97 9E 9F
A0 A9
B0 BC
C0 C7 CB CF
D0 D7 DF
E0 E2 E9
F1 F2 F4 F5 F9 FC FD
- Right-click on the top blue bar of the CL window
- Click on Properties option at the bottom
- Click on Colors tab to make the changes
- When you click on OK, you will be prompted to see if you want the changes only for the current window (top option selected by default), or for all CL windows too that you open in the future (bottom option).
OK, back to the script!
echo as we discussed earlier, does exactly what it says, it echos whatever is type after it but there must be at least a single space after echo command! The only character you can use immediately after echo command is period (.) which means there will be nothing but empty space display for the single line.
echo.
echo.
echo Please Close All Programs Before You Continue!!
echo.
echo.
echo.
I use this technique to create some empty space around the text display on the screen to make it easier for the user to see and read.
It indefinitely puts the script on hold until the user presses a key to continue.pause
Clears the screen, short for clear screen.cls
The below section is the actual meat of the script, the part that actually does all the work.
del (delete aka erase) deletes the all the files matching to the predefined condition at the specified location(s) but beware, when you delete a file or folder from the CL or using a CL script, it doesn't go to Recycle Bin, it's removed permanently!del /f /s /q "%userprofile%\Local Settings\Temp\*.*"
del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\*.*"
del /f /s /q "%userprofile%\Recent\*.*"
del /f /s /q "%userprofile%\Local Settings\History\*.*"
del /f /s /q "%userprofile%\Cookies\*.*"
del /f /s /q "%appdata%\Microsoft\Office\Recent\*.*"
del /f /s /q "%userprofile%\~*.*"
IF EXIST "%windir%\KB*.log" del /f /q "%windir%\KB*.log"
IF EXIST "%windir%\Q*.log" del /f /q "%windir%\Q*.log"
I won't get into the detail on the parameters because you can look it up with adequate explanation within the CL by typing the command followed by a space a forward slash and a question mark.
Uploaded with ImageShack.us
I will, however, say this:
- Always leave a single space between the command and each one of its parameters.
- If the directory path in question has names with spaces in between or the file/folder name is larger than 8 characters then make sure to put quotation marks at the beginning and at the end of the path:
- Use variables instead of actual system directory paths whenever you can for greater flexibility."%userprofile%\Local Settings\Temporary Internet Files\*.*"
For example, if Windows was installed at the default C drive and you knew the actual user name then all of the following would work:
A) "%userprofile%\Local Settings\Temporary Internet Files\*.*"
B) "C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\*.*"
C) "C:\Documents and Settings\TurcoLoco\Local Settings\Temporary Internet Files\*.*"
But imagine you don't know the user name or you want to give this script to your friend so he/she can use it on their computer? Then option C would no longer be valid. Or, let's say you have a Windows Vista or 7 system with the same user name, then neither B nor C would work but A would still work. This is the power of variables, it makes the script much more versatile, more efficient. I also use wild cards such as * which means all/any, so *.* means any file name with any file extension at that location.
To make this script more compatible with Vista and 7, you could modify the following lineas this:del /f /s /q "%userprofile%\Local Settings\Temp\*.*"If you click START > RUN > type temp > OK it would open up the system temp folder which is typically C:\Windows\Temp.del /f /s /q "%Temp%\*.*"
But, if you click START > RUN > type %temp% > OK it will open current user's temp folder which is:
C:\Documents and Settings\username\Local Settings\Temp in XP
and
C:\Users\username\AppData\Local\Temp in 7 (and also Vista but not certain since I don't user Vista).
IF command used with EXIST or NOT EXIST allows script to check the specified location for the specified file(s) beforehand, if the file(s) existed, it executes the command specified next, in this case del. This typically ensures that the script/user will not encounter any errors if there were no file(s) at that location. The script would automatically move on to the next line.IF EXIST "%windir%\KB*.log" del /f /q "%windir%\KB*.log"
Just as the name implies, this command quits the script and closes the CL window as well.exit
I hope this was not too overwhelming. I will get into details more as I do other scripts. Pardon the typos and feel free to post if you have any questions or comments.
Attached are the functional versions of the basic Windows Temp File Cleaner. Clean.bat which I discussed in this post is for Windows XP.
Clean7.bat is for Windows 7 machines which might work for Vista as well.
Feel free to download, modify and try these but at your own risk!![]()





Reply With Quote