In the article "Making the Most of Your Hard Disk Space, Part 2" [Windows 95 Professional, January 1998], we gave you several methods you could use to regain lost hard disk space. However, you must perform many of those methods on a regular basis to be effective. In this article, we'll discuss how to perform those procedures more conveniently.
One of the best ways to automate a task is to build a batch file containing instructions for performing the task. Although a batch file can easily handle some of the steps in the main article, other steps involve running Windows programs such as Defrag. Fortunately, unlike its predecessors, Windows 95 allows you to launch Windows programs from a batch file. Therefore, we've created a batch file, shown in Listing A, that automates virtually every step of the task.
It's important to manually test each command on your system before running the batch file. In addition, since our batch file deletes files, you should back up your system before running the batch file for the first time. You should also exercise extreme caution, ensuring that all the commands run correctly on your system. As you can see, we've added a comment before every command in the batch file to identify what the command does.
In our batch file, we've used the default directory names. If you've used different directory names, you'll need to modify the batch file to compensate for each name change. You should also remove any commands that you don't feel comfortable running on your system.
To create the batch file shown in Listing A, open Notepad, type the batch file's commands, and save it in your Windows directory as Conserve.bat. Before you can run the batch file, you'll have to create in your Windows directory a text file called Y.txt that contains nothing more than the letter Y, as shown in Figure A. Our batch file uses Y.txt to avoid prompting the user for confirmation of various functions. The batch file contains only one point that requires user intervention. Since you can't run Defrag while ScanDisk is still running, we've included a Pause command that requires user input before the batch file will continue. The user must wait until ScanDisk is finished before pressing any key to instruct the batch file to start the Defrag utility.
Figure A
The Y.txt file eliminates the need for almost all user intervention.
After you've created the batch file and Y.txt, you must close all other applications. If an application is open, the batch file may erase a temporary file that's in use.
Listing A: Conserve.bat
REM The following commands remove all files with the extensions
REM .bak, .old, .log, and .tmp from the root directory and from your
REM Windows directory. You should omit the appropriate lines if
REM you're intentionally storing backups of your system configuration
REM information in a .bak or .old file or if you're compiling a LOG
REM file that you don't want to overwrite.
Erase C:\*.bak
Erase C:\Windows\*.bak
Erase C:\*.old
Erase C:\Windows\*.old
Erase C:\*.log
Erase C:\Windows\*.log
Erase C:\*.tmp
Erase C:\Windows\*.tmp
REM The following command erases the entire contents of your
REM Windows\Temp directory. Don't execute this command unless
REM all other applications are closed.
REM The <y.txt appended to the end of the command prevents
REM the command from asking for permission to delete the files.
REM You can make the command ask for permission to delete all the
REM files in the directory by removing the <y.txt. If you want the
REM command to ask for confirmation before deleting each individual
REM file, remove <y.txt and replace it with /P .
Erase C:\Windows\Temp\*.* <y.txt
REM The next set of commands are for Internet Explorer 3 users only.
REM These commands empty your cache and history directories. If you're
REM using Internet Explorer 4 or have information in these directories
REM that you want to preserve, you should omit these commands.
REM The <y.txt appended to the end of the following commands,
REM prevents them from asking for permission to delete
REM the files. You can make the command ask for permission
REM by removing the <y.txt from the end of the commands.
REM If you want the command to ask for confirmation
REM before deleting each individual file, remove <y.txt and
REM replace it with /P .
Erase C:\Windows\Tempor~1\Cache1\*.* <y.txt
Erase C:\Windows\Tempor~1\Cache2\*.* <y.txt
Erase C:\Windows\Tempor~1\Cache3\*.* <y.txt
Erase C:\Windows\Tempor~1\Cache4\*.* <y.txt
Erase C:\Windows\History\*.* <y.txt
REM This set of commands is for Internet Explorer 4 users only.
REM These commands empty your cache and history directories. If you're
REM using Internet Explorer 3 or have information in the directories
REM that you want to preserve, you should omit those commands.
REM You'll also have to customize the directory names, since they
REM are system-specific. For information on determining the appropriate
REM directory names, see the article "Making the Most of Your Hard Disk Space,
REM Part 2" [Windows 95 Professional, January 1998].
REM The <y.txt appended to the end of the following commands
REM prevents them from asking for permission to delete the
REM files. You can make the commands ask for permission to
REM delete all the files in the directory by removing
REM <y.txt from the end of the commands. If you want the
REM commands to ask for confirmation before deleting each
REM individual file, remove <y.txt and replace it with /P .
Erase C:\Windows\Tempor~1\Ljz3akip\*.* <y.txt
Erase C:\Windows\Tempor~1\Wca56jbi\*.* <y.txt
Erase C:\Windows\Tempor~1\Epiiyh7y\*.* <y.txt
Erase C:\Windows\Tempor~1\Ckzus002\*.* <y.txt
Erase C:\Windows\History\*.* <y.txt
REM The next command runs ScanDisk and repairs any damaged files on
REM your hard disk. There are several switches you can use with this
REM command. These switches include
REM DRIVE Specifies the hard disk to check
REM /A Scans all nonremovable hard disks
REM /N Starts and closes ScanDisk automatically
REM /P Prevents ScanDisk from correcting errors that it encounters
ScanDisk /A /N
REM The Pause command that follows forces the batch file to wait until the user
REM presses any key before continuing with the next command. Otherwise, the batch
REM file will attempt to start Defrag while ScanDisk is still running. Since ScanDisk
REM and Defrag can't run simultaneously, you must wait until ScanDisk
REM finishes before pressing a key to launch Defrag.
Pause
REM The following command tells Defrag to defragment your hard disk.
REM There are several switches you can use with this command. These
REM switches include
REM DRIVE Specifies which hard disk to defragment
REM /ALL Defragments all nonremovable hard disks
REM /F Defragments files and free disk space
REM /U Defragments files only
REM /Q Defragments free space only
REM /CONCISE Hides details during defragmentation
REM /DETAILED Displays details during defragmentation
REM /NOPROMPT Makes Defrag run automatically with no required user intervention.
Defrag /ALL /F /DETAILED / NOPROMPT
Conclusion
Instead of manually running through the procedures we outlined in "Making the Most of Your Hard Disk Space, Part 2, " you can easily create a batch file to do routine hard disk cleaning. In this article, we've shown you how to create such a batch file.
-----------------------------
This article is reproduced from the January 1998 issue of Windows 95 Professional. Windows 95 Professional is an independently produced publication of The Cobb Group. No part of this article may be used or reproduced in any fashion (except in brief quotations used in critical articles and reviews) without prior consent of The Cobb Group. To contact The Cobb Group, please call (800) 223-8720 or (502) 493-3200.
Copyright © 1998 The Cobb Group, a division of Ziff-Davis Inc. The Cobb Group and The Cobb Group logo are trademarks of Ziff-Davis Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis is prohibited.