Tuesday, June 16, 2026

Creating a Simple PC Cleanup Tool with Batch Commands

 1. Copy and paste the script to Notepad or any text editor.

2. Save the script as diskcleantool.bat or diskcleantool.cmd.

3. Make sure to use a desktop or folder so that you can easily locate the file.

4. Right-click the file and run as administrator.

Batch Script 

 @echo off
echo Cleaning system junk...
del /s /f /q %temp%\*
del /s /f /q C:\Windows\Temp\*
del /s /f /q C:\Windows\Prefetch\*
echo Cleanup complete.
pause

 --------------------------------------------------------------------------------------------------------------------------

Purpose of the Program

This Windows Batch Script is designed to remove temporary and cached files from common system storage locations. Its main goal is to free up disk space and potentially improve system performance by deleting unnecessary files that accumulate over time.

The script targets three locations:

  1. The current user's temporary files folder.
  2. The Windows temporary files folder.
  3. The Windows Prefetch folder, which stores data used to speed up application startup.

After completing the cleanup process, the script displays a completion message and waits for the user to press a key before closing.

Line-by-Line Explanation

Line 1: @echo off

Explanation:

  • The echo off command prevents commands from being displayed as they execute.
  • The @ symbol hides the echo off command itself.

Purpose:
Makes the script output cleaner by showing only messages intended for the user instead of every command being executed.

Line 2: echo Cleaning system junk...

Explanation:

  • The echo command displays text on the screen.

Purpose:
Informs the user that the cleanup process is starting.

Output: Cleaning system junk...

Line 3: del /s /f /q %temp%\*

Explanation:

  • del = Deletes files.
  • /s = Deletes files from all subdirectories.
  • /f = Forces deletion of read-only files.
  • /q = Quiet mode (does not ask for confirmation).
  • %temp% = Environment variable pointing to the current user's temporary folder.
  • \* = Targets all files in that folder.

Purpose:
Removes temporary files created by applications for the currently logged-in user.

Example Location: C:\Users\Username\AppData\Local\Temp 

Line 4: del /s /f /q C:\Windows\Temp\*

Explanation:
Deletes all files inside the Windows system temporary directory and its subfolders.

Purpose:
Removes temporary files generated by Windows and system processes.

Notes:

  • Administrative privileges may be required.
  • Some files may remain because they are currently in use by the operating system.

Line 5: del /s /f /q C:\Windows\Prefetch\* 

Explanation:
Deletes all files in the Windows Prefetch folder.

Purpose:
Attempts to remove cached startup information used by Windows to speed up application loading.

Notes:

  • Windows automatically recreates Prefetch files when needed.
  • Frequent deletion is generally unnecessary because Windows manages this folder automatically.

Line 6: echo Cleanup complete.

Explanation:
Displays a message after the cleanup commands finish.

Purpose:
Notifies the user that the script has completed its tasks.

Output: Cleanup complete.

 Line 7: pause

Explanation:
Stops the script and waits for the user to press a key.

Purpose:
Allows the user to read the completion message before the command window closes.

Output: Press any key to continue . . .

Advantages

  • Frees storage space by removing temporary files.
  • Simple and easy to execute.
  • Requires very little system resources.

Limitations

  • Cannot delete files currently being used by Windows or running applications.
  • May require administrator privileges for system folders.
  • Deleting Prefetch files usually provides little performance benefit because Windows rebuilds them automatically.

Conclusion

This batch script serves as a basic system maintenance utility that removes temporary files from user and system directories. It automates a common cleanup task and provides feedback to the user throughout the process. While useful for removing unnecessary files, it should be used carefully because some targeted folders are managed automatically by Windows.