How to Create a Disk Cleanup BAT File

by Nick Davis

As you visit websites and install programs on your computer, a copy of each website you visit and temporary setup files are stored on your computer's hard drive. These files consume a large amount of space and can slow down your computer's performance. To remove these unnecessary files, you don't have to buy a third-party application. The Windows operating system includes a utility, Disk Cleanup, for cleaning up your hard drive. You can even create a batch (BAT) file using a text editor to automate the cleanup process.

Creating the BAT File

1

Open your computer's text editor, WordPad, Notepad or other text editor. The text editor will open to a blank text editor file.

2

Enter “c:\\windows\\system32\\cleanmgr.exe /dc /sageset: 1” on the first line of the blank text editor file. Press the “Enter” or “Return” key on your computer's keyboard.

3

Enter “c:”. Press “Enter” or “Return.” Enter “cd \\”. Press “Enter” or “Return.”

4

Enter “cd c:\\windows\\prefetch”. Press “Enter” or “Return.” Enter “del *.* /q”. Press “Enter” or “Return.”

5

Click “File,” “Save As.” Click on the down arrow on the box next to “Save in:.” Double click on “C:\\,” “Windows,” “System32.”

6

Click on the down arrow on the box next to the wording “Save as type.” Select “All Files.”

7

Enter “clean.bat” in the “File name:” box. Click “Save.”

8

Click “File,” “Exit.”

Setting the Attributes of the Clean.Bat File

1

Click “Start,” “My Computer.”

2

Double click on “C:\\” drive icon. Double click the “Windows” folder. Double click the “System32” folder.

3

Double click the “clean.bat” file to run the batch file. The “Disk Cleanup Settings” dialog box will open.

4

Click on the items you want the Disk Cleanup utility to remove during the cleanup process. Click “OK” once you are finish selecting the items.

5

Right-click on the “clean.bat” file in the “System32” folder. Click “Edit.” The batch file will open in the text editor you used to create it.

6

Replace the first line of the batch file to “c:\\windows\\system32\\cleanmgr.exe /dc /sagerun: 1”.

7

Click “File,” “Save.” Click “File,” “Exit\" to close the text editor.

Automating the Clean.bat File

1

Click “Start,” “Control Panel.” Double click the “Scheduled Tasks” icon.

2

Click “File,” “New,” “Scheduled Task.”

3

Enter “Cleanup” in the box highlighted “New Task.” Press “Enter” or “Return.”

4

Right-click on “Cleanup.” Click “Properties.”

5

Click on the “Browse” button next to the heading “Run.” Navigate to the “C:\\”, “Windows,” “System32” directory. Click on the “clean.bat” file to select it. Click “Open.”

6

Click on the “Schedule” tab. Select when you want the Disk Cleanup batch file to run under the “Schedule Task:,” “Start time:” and “Schedule Task Daily” headings. Click “Apply,” “OK.”

Tips

  • If you don't want the Disk Cleanup batch file to run automatically, skip the steps in the “Automating the Clean.bat File” section.
  • You can run the Disk Cleanup batch file by navigating to the “System32” directory and double clicking the “clean.bat” file.

Video of the Day

Brought to you by Techwalla
Brought to you by Techwalla

Items you will need

About the Author

Nick Davis is a freelance writer specializing in technical, travel and entertainment articles. He holds a bachelor's degree in journalism from the University of Memphis and an associate degree in computer information systems from the State Technical Institute at Memphis. His work has appeared in "Elite Memphis" and "The Daily Helmsman" in Memphis, Tenn. He is currently living in Albuquerque, N.M.

More Articles

Photo Credits