You want to defragment a volume to improve disk access performance.
Using a graphical user interface
Using a command-line interface
The defrag utility is the command-line version of the Disk Defragmenter application. Run the following command to perform an analysis of the D drive:
> defrag d: /a
Add the /v option to see similar information to the View Report button in Disk Defragmenter:
> defrag d: /a /v
Lastly, just include the drive and /v (for verbose output) to perform a defragmentation of the volume:
> defrag d: /v
You can force a defragmentation even if disk space is low by including the /f option.
Using a downloadable software
Diskeeper from http://www.diskeeper.com and PerfectDisk from http://www.raxco.com have options for defragmenting disks, including scheduling defragmenting, deploying on multiple machines, and defragmenting boot files. Diskeeper runs in the background and defrags files as they become fragmented, so your disks stay defragmented automatically. Both tools offer trial downloads, although if you keep using them, you'll have to pay.
When you save a file on a volume, Windows tries to save the file in one contiguous section on the disk. However, as the disk becomes full, the largest available contiguous sections of the disk become smaller and smaller. New files eventually become spread over multiple sections of the disk; this is called fragmentation. Fragmentation leads to decreased disk access performance because Windows has to access multiple sections of the disk to piece together a single file.
The Windows defragmentation feature helps alleviate this problem by scanning a disk and attempting to combine the sections of files in larger contiguous portions. To perform a full defragmentation on a volume, the target volume needs to have at least 15% free space. This is necessary because Windows needs some space to store file fragments it is trying to piece together. If you have less than 15% available, you'll need to free up some space first. See Recipe Recipe 7.7 for more details.
You can determine how badly a volume is fragmented by analyzing the volume. All three solutions provide options for generating a report that provides details on the fragmentation level of a volume. The report will also recommend whether you should perform a defragmentation or not. This is useful only as a general guide because it may always recommend that you perform a defragmentation even after you've just run one.
You should consider performing periodic defragmentation on heavily used volumes that have become more than 50% utilized. As disk space decreases on a volume, the level of fragmentation generally increases because the number of contiguous sections of disk decrease. If you have really large disks that are rarely more than 25% used, performing a defragmentation will not likely be of much benefit.
Recipe 7.7 for cleaning up a volume; MS KB 283080, "Description of the New Command Line Defrag.exe Included with Windows XP," MS KB 305781, "How To Analyze and Defragment a Disk in Windows XP," and MS KB 312067, "Shadow copies may be lost when you defragment a volume"