Copyright Michael Karbo, Denmark, Europe.

  • Next chapter.
  • Previous chapter.

    Chapter 9. Fragmented files

    Hard disks are getting bigger and bigger, and likewise programs. This means that a hard disk is rapidly worn down. At the same time the numbers of files are increased; if you, for example, take digital photographs or record music in mp3 format, then you can end up with an enormous amount of data stored on your drives.


    It's a good thing that a computer is used and the amount of data increases. But the more data you store, the more you wear your hard disk down. The case is, you see, that files don't just have a particular position on a hard disk. Every time you make an alteration in a file (and this happens all the time) then it is stored in a new position on the hard disk.

    But the files aren't only stored in one place. They are often split up into small parts (fragments), which are spread over the hard disk. The idea being that the room on a hard disk should be fully exploited. This is the way both the file systems (FAT and NTFS) are designed: the files are fragmented when there are unoccupied holes in the hard disk, which can be filled up.

    This fragmentation means that it takes longer to scan in a particular file from a hard disk. Maybe the file is spread over five or seven different places on the disk and the reading head has to move around collecting all the fragments into a complete file. This makes the computer work more slowly because the hard disk has to work harder.

    Large hard disks help

    Fragmenting can become a serious problem for a computer's output. And the less room there is on a disk, the bigger the problem. Can you imagine a hard disk with 40 GB, where there is only 1 GB unoccupied room. The files here will, in time, be fragmented more and more. There will never be enough room to write in a larger file in one unbroken pack; it will have to be chopped up into smaller and smaller pieces every time it is rewritten.

    It is, therefore, a good rule to have 40% unoccupied room on a hard disk. This might sound like a lot but there does have to be a big margin, if fragmentation is to be reduced. If you come under 25 % unoccupied room, then fragmentation will really seriously start taking place. It's also important to use NTFS for the formatting of big hard disks, because this causes much less fragmentation.

    Luckily, hard disks have become much cheaper so it shouldn't be a problem having a lot of unoccupied room. Always buy a big disk take 160 rather than 120 GB and so on, and don't be afraid of putting an extra disk in your computer.

    Gather the files together

    Whatever you do, fragmentation is unavoidable most of the files will be split up more and more as time goes by. This decline can be hold at bay by two means: more room on the disk and software for defragmentation.

    Defragmentation is a process, where the files are bunched together in whole lumps on the hard disk. This is done with a special program, which heals the files by moving around on the hard disk's individual sectors. When the process is finished, the individual files can be read in one swoop, without the reading head having to seek in east and west for different fragments.

    In Windows XP the computer's drive can be defragmented in several ways. You can for example, right click on a drive in Windows Explorer. This gives access to the selection of the menu point Properties, which gives access to the function Disk defragmenter:

    Then you get an uncomplicated screen display where you can select the drive you want to defragment:

    Figure 49. The simple program Disk defragmenter, which accompanies Windows XP.

    Daily routine

    Unfortunately Windows XP's tool for fragmenting is not particularly effective. It is, in fact, completely unsuitable for the large amounts of data found in modern computers. You really ought to defragment every day but this is rather difficult with the tool in Windows XP, which isn't very intelligent.

    You can try programming Windows so that it defragments daily. This is done with the tool Task Manager, which can be found in the control panel.

    You can define here that the program Disk defragmenter should run daily at a certain hour:

    Figure 50. Disk defragmentation ought to be run every day, if a computer's hard disk is to be in top form.

    From the command line

    The program Disk defragmenter can also be run from the command line. Let me use this as an opportunity to show you how you can create a little script, which can activate the Disk defragmenter.

    1.    First we will see how you can run a disk defragmentation from the command line.

    2.    Try typing the Windows-key+r. The letter r stands for run. The dialog box Run is therefore opened.

    3.    Then type in the command defrag c: -f, as shown below and click on the button OK:

    4.    The program Disk defragmenter now performs in completely different way. It is done in a text-based command window:

    Figure 51. Disk fragmentation is done here from the command line.

    Create a script

    One of the advantages of the command line version of Disk defragmenter is that the program can be summoned with different commands, for example during the computer's start-up. We will exploit this here to create a little script, which can perform on command.

    1.    Use, for example, Windows Explorer to find a folder where the script can be placed. Or use the desktop.

    2.    Right click on the folder or on the desktop and select New --> Text document:

    3.    Type in the file name defrag.bat, type Enter, and click on Yes, when Windows cautions on the type of file:

    4.    You have now created a so-called batch file. Right click on it and select the menu Edit:

    5.    Batch files are small text files. They are, therefore, edited with the text editor, which is found in Windows and this is usually Note pad. Type in the two lines you see here (as I assume you have a C and a D drive, which are to be defragmented):

    6.    Save the file again with Ctrl+s, and close the editor.

    7.    You have now a batch file you can activate with a double click. When you do this all the commands (there are two here), listed in the file, will be performed one after the other.

    8.    In this case the C drive is defragmented first and then the D drive in a window like the one shown in Figure 51. The window automatically closes when the operation is finished.

    9.    The batch file defrag.bat can now be used to start a defragmentation.

    The batch file can also be activated at certain times with the help of the Task manager (see Figure 50).


    The tool Disk defragmenter, which is to be found in Windows XP, is really developed by the firm Executive Software. Windows contains as very primitive version of the professional program Diskeeper, which can be warmly recommended. It can be purchased from the firm's web site ( for a couple of hundred kroner.

    Figure 52. Diskeeper 8.0 is at the time of writing the latest version of this excellent tool.

    Diskeeper is easy to use and has a user-friendly program, which is really good at giving information about the condition of the hard disks, see the following two figures:

    The best thing with Diskeeper is the function Set It and Forget It. You give the program the right to defragment a computer's drive when it is necessary. Everything is done behind the scenes. The only thing you will be aware of is the sound from the hard disk when Diskeeper starts up. It doesn't seem to delay the other operations in the computer.

    Figure 53. A really professional tool that does the job.

  • Next chapter.
  • Previous chapter.

  • Book overview.