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
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
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
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.