TechBrew

Informative geekery on software and technology

Defrag a Single File or Set of Files in Windows

August 20th, 2008 by Mark Woodman

Ever wanted to defragment a certain file or collection of files on your Windows PC, without defragging the entire hard drive? Here’s why and how you can do it:

Don’t Bring Me Down

I recently noticed that one of my oft-used Windows applications was getting slower and slower. After checking the usual suspects in Task Manager (Windows Search, Norton AV, you know who you are), I also checked to see if my hard drive needed to be defragmented. At first glance, the answer was no: the defrag tool reported “You do not need to defragment this volume”. I looked at the volume report, however and saw that many of the worst-fragmented files were used by my oh-so-slow application.

Any time an application needs to read or write to heavily-fragmented files, it has to go on a treasure hunt all over the hard drive platter. Since disk I/O is an expensive operation, defragging those files can boost application performance considerably. It might also save you from some nasty crashes.

The problem is that there is no guarantee which files the Windows Defrag Tool will touch. You can defrag the whole disk only to find out it skipped your files anyway. Yeah, that happened to me. Twice more than I care to admit. Mr Gates, I’d like my 2 hours back.

So I did a treasure hunt of my own, and found a fast and free tool designed to solve this very problem…

Contig To The Rescue

Contig v1.54 is a free command-line tool that works on Windows NT, XP, 2000, and Vista. It will analyze and defragment a file or a set of files matching a wildcard. Contig is fast, tiny at 55KB, easy to use, and can even be killed in the middle of processing without corrupting your drive. Here’s how to start single-file defragging in 5 minutes, or your next pizza is free:

  1. Download Contig.zip, and extract Contig.exe in a directory of your choice.
  2. Open a command line, and type in the location of Contig.exe, followed by the -v switch, followed by the location of the file you want to defrag. If either location has a space in the path name, be sure to enclose both locations in quotes. Here’s how it looks in action:
    C:\>”C:\tools\Contig.exe” -v “C:\System Volume Information\catalog.wci\00010005.ci”

    Found a free disk block at 14025352 of length 32740 for entire file.
    Moving 32688 clusters at file offset cluster 0 to disk cluster 14025352
    File size: 133890048 bytes
    Fragments before: 1126
    Fragments after : 1
  3. If you want to defrag a set of files using a wildcard pattern, then just use the -s switch and a wild-carded path. Like so:
    "C:\tools\Contig.exe" -s "C:\music\*.mp3"

It’s really that easy. Contig also has a couple of other switches to either just analyze the files or run quietly. See the home page for documentation. Happy Defragging!

Photo (CC) by Justin Marty

Trackback URI | Tags: How-To

2 responses so far ↓

Leave a Comment