Introduction: DIY Computer Clean Up Batch Script

About: I'm a freelance web developer. I love to make websites, whether this is a normal site, a blog or a WordPress-driven website. As a web developer, I'm constantly improving my knowledge and I use modern tools and…

Welcome to my second tutorial, today we're going to talk about how to make a batch script that cleans up your computer.

If you already know what a batch file is (or if you just want the script) you can proceed to step 3. If not proceed to the next step in this instructable. There I will explain what we're going to make in more detail.

Note: this turorial is for educational purposes only. I am not responsible for anything that might happen to your computer.

Step 1: Step 1 - What Are We Going to Make

In this instructable we're going to code a script that cleans up most of the junk files on your computer such as, .temp files, log files, temp help files, disk check files, temp backup files and much more. Besides that, we are going to make a interface for the program, so that the user can control it. (and it looks awsome).

If you want the script with no interface, go to step 3. If you want to learn how to make the interface and how to modify the existing script, go to the next step.

Note: If you face any problems running the scripts, feel free to contact me, or to post a comment below.

Step 2: Step 2 - How to Make It Work

Note: I have added some comments inside of the script, so you guys know what every line of code does.

1. Click Start.

2. Type: Notepad in the Run box and press Enter.

3. Once Notepad is open, copy the code below.

4. Click File and then Save, and then navigate to where you want to save the file. For the file name, type "test.bat", and if your version of Windows has a "Save as type" option, choose "All files", otherwise it will be saved as a text file. Once you have saved your file, exit Notepad.

Note: The file suffix name must be ".bat".

5. To run the batch file, double-click it like any other program. Once the batch file has completed running it closes automatically.

Step 3: Step 3 - Script 1 (without Interface)

At the bottom of this step you will find the finished program without the interface. Just execute the program and it will do his job. :)


@echo off

echo Cleaning system junk files, please wait…
REM displays a line of text

del /f /s /q %systemdrive%\*.tmp
del /f /s /q %systemdrive%\*._mp
del /f /s /q %systemdrive%\*.log
del /f /s /q %systemdrive%\*.gid
del /f /s /q %systemdrive%\*.chk
del /f /s /q %systemdrive%\*.old
del /f /s /q %systemdrive%\recycled\*.*
del /f /s /q %windir%\*.bak
del /f /s /q %windir%\prefetch\*.*
rd /s /q %windir%\temp & md %windir%\temp
del /f /q %userprofile%\cookies\*.*
del /f /q %userprofile%\recent\*.*
del /f /s /q “%userprofile%\Local Settings\Temporary Internet Files\*.*”
del /f /s /q “%userprofile%\Local Settings\Temp\*.*”
del /f /s /q “%userprofile%\recent\*.*”

REM /f: force deleting of read-only files
REM /s: Delete specified files from all subdirectories.
REM /q: Quiet mode, do not ask if ok to delete on global wildcard
REM %systemdrive%: drive upon which the system folder was placed
REM %windir%: a regular variable and is defined in the variable store as %SystemRoot%. 
REM %userprofile%: variable to find the directory structure owned by the user running the process

echo Cleaning of junk files is finished!
REM displays a line of text

echo. & pause
REM echo.: Displays a single blank line on the screen.
REM pause: This will stop execution of the batch file until someone presses "any key"

Step 4: Step 4 - Script 2 (with Interface)

This part of the script is slightly harder than the one in the previous step, but if you take your time to read this, you will see that it's not hard to make a script in DOS (or a other language).

The code below will add a simple menu with a logo to our existing program. When the script is executed the user can choose between a couple of options. You can add, edit or delete options your self if you want. I will explain how to do that now.

To add a option, first update your menu. (see picture 2) After that you can add the line of code below. (see picture 3)


%errorlevel% equ 4 goto customName if

Now, you can add the block of code below. (see picture 4)

Note: it is better to add the new option after the exit and start option. Also, try to keep your code clean and organized. This is easier for later if you want to change something.

%errorlevel% equ 2 goto about if
REM custom option
:customName

/////add here what your option does///////////

pause
goto mainmenu


Just place the code from step 3 in the area I mentioned below.


@echo off

:mainmenu
cls

........................................
..........,,:+++???????+++:,,...........
......,~=============~~~~~::::==,.......
.....~===============~~~~~:::::,,=......
.....================~~~~~:::::,,=,.....
.....,:==============~~~~~:::::===......
.....,,::::=+++======~~~++++=====,......
.....,,:::::::~~~~~~~~~==========,......
......::::::::~~~~~~~~~==========.......
......,:::::::~~~~~~~~==========,.......
......,:::::::~777777777========,.......
......,:::::::II777~77777=======,.......
.......,::::::~~77~~~777~=======........
.......,:::~III~~~~~~~===77====,........
.......,::::IIII~~~~~~~77777===,........
........:::IIII~~~~~~~~~7777===.........
........:::::I+~~~~~~7==77=~==,.........
........,:::7III777~I777777===,.........
........,::::III777~777777====,.........
.........:::::~~~~~~=7~=======..........
.........,::::~~~~~~~~~======,..........
.....,,,,,::::~~~~~~~~~======,..........
....,,,,,,,,,:~~~~~~~~~==,,.............
........................................
........................................

echo *********************
echo * CleanUp Menu*
echo *********************
echo * 1. Start CleanUp *
echo * 2. About CleanUp*
echo * 3. Quit *
echo *********************
choice /C:123 >nul

if %errorlevel% equ 1 goto start if %errorlevel% equ 2 goto about if %errorlevel% equ 3 goto exit

REM closes the program
:quit
exit /b

REM starts the clean up
:start

******PUT SCRIPT FROM STEP 3 HERE ******

pause
goto mainmenu

REM shows info
:about
echo *********************
echo * This batch file deletes most* echo * commen temp files stored on* echo * the windows install directory*
echo **
echo * Written by Kevin Tipker*
echo * 28/02/2016*
pause
goto mainmenu

Step 5: Step 5 - Finished

I hope you have enjoyed this instructable about scripting a batch file that cleans up your computer.

The only thing that rest me is to ask you for some feedback. Also, I would love to hear from you guys what I should cover in my next instructable.
Web design or a PHP tutorial? Let me know in the comments below. :)