When the end of the week rolls around, I try to find an hour to clean off my desk of accumulated papers, files, books, and other stuff. If I don't do this regularly, my work tends to slow down and my productivity starts to decline. There are probably several reasons for this: more stuff on my desk makes it harder for me to find stuff when I need it; less free desk space means I have to take time moving stuff around when I need to find a place to put something; and stuff piled high tends to distract me from the things I need to get done to keep earning a living.
Hard drives can get cluttered too, and as they grow in size and computers become ubiquitous tools and toys for both business and entertainment, the problem of hard drives getting filled up with useless junk has similar implications for both our work and leisure. So let's look at a few simple ways one can de-junk hard drives on Windows XP machines.
Disk Cleanup is an easy-to-use tool that lets you get rid of some of the more useless files you tend to accumulate under Windows. Using Disk Cleanup you can easily delete temporary Internet files (mostly cached versions of web pages you've visited recently), downloaded program files like Java applets and ActiveX controls, temporary files created by Office and other applications, network files that have been saved locally as offline files, and deleted files that have been moved to the Recycle Bin. The table below shows a list of the folders that Disk Cleanup can purge on a typical boot volume:
Disk Cleanup options
To free up even more space on your drive, Disk Cleanup also lets you uninstall any optional Windows components or third-party applications you no longer use, and even System Restore points that are no longer needed, as Figure 1 shows:
Figure 1: Using Disk Cleanup to remove unnecessary Windows components, programs, and restore points
While you can de-junk a volume manually by right-clicking on it in My Computer, selecting Properties, and clicking on Disk Cleanup in the General tab, a much better way to maintain your disks is to automate the cleaning process. Click on Start -> Run; then type
cleanmgr /sageset:1 and click on OK. This opens a Settings dialog that lets you specify which kinds of files you want to automatically delete when Disk Cleanup runs (Figure 2):
Figure 2: Specify which types of files to automatically delete
Note that this dialog lets you delete additional file types that aren't listed in the table above and therefore can't be specified when you run Disk Cleanup manually. These additional file types include:
If you run Disk Cleanup automatically, you can't delete Catalog files for the Content Indexer, however.
Once you've selected your Disk Cleanup settings, click on OK; the settings will be stored in the Registry for future use. Now open Scheduled Tasks in Control Panel and double-click on Add Scheduled Task. Walk through the Scheduled Task Wizard and specify Disk Cleanup as the application you want to run, a schedule for running it, the time it will run, and the credentials under which the program will run. Make sure you select the check box that lets you open the Advanced Settings for the task, and in the text box labeled Run, append
/sagerun:1 to the end of the command string (Figure 3):
Figure 3: Creating a scheduled task that will run Disk Cleanup with pre-saved settings
If you want to have even more granular control over how your disks are de-junked, you can create a second set of stored Disk Cleanup settings with Start -> Run ->
cleanmgr /sageset:2 -> OK. You can then create a separate scheduled task that runs
cleanmgr /sagerun:2 to schedule when your second Disk Cleanup operation runs. For example, you could run Disk Cleanup once a day to delete temporary files at the end of your workday for security reasons, and once a month to delete files from your Recycle Bin. You can even create additional sets of Disk Cleanup settings ranging in number from
Mitch Tulloch is the author of Windows 2000 Administration in a Nutshell, Windows Server 2003 in a Nutshell, and Windows Server Hacks.
Return to the Windows DevCenter.
Copyright © 2009 O'Reilly Media, Inc.