Windows Tips: The Fast, Simple Way to Defragment Your Disks

Today's Best Tech Deals

Picked by PCWorld's Editors

Top Deals On Great Products

Picked by Techconnect's Editors

You say you'd defragment your hard drive if only doing so weren't so time-consuming? Well, have I got a batch file for you. (Before you defragment, you should scan your disk for errors. For tips on automating your disk scans in Windows XP, read my September 2003 column at Check Your Disks for Errors, With a Single Click.)

First, the manual defragging approach: Click Start, Programs (or All Programs), Accessories, System Tools, Disk Defragmenter, Defragment (see Figure 1

Figure 1: Windows' defragmenter tool uses a four-color graph to represent the disk space that can be recovered on your drives.
). You can defrag only one drive at a time this way, but Windows' defragging tool shows the drive's fragmentation graphically and lists all your drives, so you can defragment one after another without a lot of clicking through dialog boxes.

It's always best to defrag a disk when it's not in use. To set up Windows to defrag a drive automatically at such a time, start by opening Notepad or another text editor, and type defrag.exe followed by a space, the drive letter, and a colon.

A drive that's low on disk space may balk at defragging, so type a space and -f to force Windows to defrag it anyway. Windows can also generate a report on the defrag when it's done: Type a space and -v to get all the details available. Next, enter > (a greater-than symbol), followed by the path to a text file that will log the results. (Note: If a text file of that name in that location already exists, it will get overwritten.) Be sure to place quotation marks around your path if it contains any spaces, or if It uses long file or folder names.

So after all that, your command line might look like this: defrag.exe c: -f -v >"e:\doc\defrag report.txt" (your path and file name may differ, of course). Finally, press <Enter>.

If you want to defrag more than one drive, create a command line for each one, changing the drive letter and the file name and path as necessary (see Figure 2

Figure 2: Set custom defrag commands for each of the drives on your system with a simple batch file.
). When you're done, choose File, Save, and save the file to a convenient location. Make sure to use the .bat or .cmd file extension.

Now any time you want to defragment the drives, just double-click the .bat or .cmd file you created. (Or drag the file's icon from Windows Explorer or any folder window and drop it onto your Start menu to create a shortcut there.)

Finally, Windows' Scheduled Tasks utility lets you defragment automatically at the time of your choice. To open this tool, click Start, Programs (or All Programs), Accessories, System Tools, Scheduled Tasks. Double-click the Add Scheduled Task icon, and click Next. When prompted for the program to run, click Browse and locate your batch file. Select it and click Open. Follow the remaining prompts to make the disk defragmenting occur whenever you want (see Figure 3

Figure 3: Use Windows' Scheduled Tasks tool to automate your disk defrags by launching the defrag batch file you created.
).

Scheduled Tasks requires that you log on using a password-protected account; you supply your Windows log-in password as part of the scheduling process. For a way to work around this, see Lincoln Spector's Answer Line column from January 2003, Synchronize Important Folders on Two Computers.

1 2 Page 1
Page 1 of 2
  
Shop Tech Products at Amazon