Utility SpotlightFile-by-File Defragmentation with Contig
Most windows defragmenters work by optimizing your entire drive, typically a time-consuming process. But to boost performance, sometimes only certain frequently used files may need to be defragmented, especially if they're large and scattered across multiple non-contiguous clusters. Microsoft's free Contig tool can help by quickly and efficiently optimizing specific files or directories.
Contig is another solid utility written by Mark Russinovich for Windows Sysinternals. You can download the tool from the Sysinternals Web site.
Like most Sysinternals apps, no installation is necessary; just run the contig.exe file. Contig is a command-line utility, so you'll need to launch it from a command console and specify one or more of the program's options. You can apply Contig to a single file or directory or multiple objects via wildcards.
Running Contig by itself displays the tool's various options, as shown in Figure 1.
Figure 1 Running Contig at the command line shows the available options. (Click the image for a larger view)
The following are more detailed explanations of each option listed here:
Contig [-v] [-a] [-q] [-s] [filename]
-v—A verbose option. This tells Contig to print to the screen all information about the defrag. It displays the name and location of every file included in the optimization, indicating the number of fragments used by each one.
-a—An analyze option. Contig simply analyzes the file or files you target for defragmentation without actually optimizing them. This option helps identify which files get heavily fragmented, especially on a regular basis.
-q—A quiet option. This switch overrides the –v option, forcing Contig to run in quiet mode. The only information you'll see on the screen is a summary of the operation after it's complete.
-s—A subdirectories option. This switch will apply the optimization recursively throughout all subdirectories when targeting a file using wildcards. For example, typing contig –s *.log will optimize all .LOG files in the parent directory and all its subdirectories.
[filename]—Finally, you must specify the file or directory you wish to optimize, either by a specific name or through wildcards.
You can even use contig to create a new file. This ensures that the file is already optimized and using contiguous clusters. The command for creating a new file is "contig –n [filename] [size]". For example, to create a file named inventory.doc that's 1KB in size, type contig –n inventory doc 1024.
Contig works by tapping into the Windows built-in defragmentation support. The tool first scans your disk to map out the location and size of any free areas. It then finds the location of the file, files or directories that you targeted in the defrag. Then it determines if the file can be optimized, depending on the disk's free areas and the amount of fragmented clusters used by the file. If necessary, it then defrags and moves the file or files into the free areas.
As a handy option, copy contig.exe to your Windows or System32 directory, or another location in your path, so that you can run it from anywhere on disk.
Contig is compatible with clients running Windows XP or later, including Windows 7, and servers running Windows Server 2003 or later.
Lance Whitney is an IT consultant, software trainer and technical writer. He has spent countless hours tweaking Windows workstations and servers. Originally a journalist, he took a blind leap into the IT world back in the early 1990s.