The long-awaited version 4 is finally out. The program is now called “MyDefrag”, because it has a scripting language and you can customize just about every aspect of it. It is no longer the “JK” (Jeroen Kessels) defragger, but “my” (your) defragger!
|
The last version of JkDefrag is still available from this page, see below. But it is no longer supported.
JkDefrag is a disk defragmenter and optimizer for Windows 2000/2003/XP/Vista/2008/X64. Completely automatic and very easy to use, fast, low overhead, with several optimization strategies, and can handle floppies, USB disks, memory sticks, and anything else that looks like a disk to Windows. Included are a Windows version, a commandline version (for scheduling by the task scheduler or for use from administrator scripts), a screensaver version, a DLL library (for use from programming languages), versions for Windows X64, and the complete sources.
Install
There is no “setup” or “install” and no configuration file. All you have to do is download the zip and unpack anywhere you like. The programs are ready to run, even from memory stick or cdrom. The zip contains the following 3 programs:
- JkDefrag.exe
- Windows version. This is what most people will use. No installation or configuration necessary, it’s ready to run and will automatically process all the mounted, writable, fixed volumes on your computer
- JkDefragCmd.exe
- Commandline version. Specially designed to be run automatically in the background, or from administrator scripts. See the “Commandline” chapter below for a list of commandline options, and the “Frequently Asked Questions” on how to run it automatically with the Windows Scheduler.
- JkDefragScreenSaver.scr + JkDefragScreenSaver.exe
- Screen saver version. Move (or copy) these two files to the “windows” folder on your harddisk (usually “c:Windows” or “c:Winnt”). It will automatically become visible in the list of screen savers as “JkDefrag screensaver” and can be used just like any other screensaver (right-click somewhere on your desktop and select Properties/Personalize, then select the Screen Saver tab).
Note: on Vista the screensaver only works with User Account Control turned off (see Control Panel, User Accounts, Turn User Account Control on or off).
Note: screen savers do not lengthen the life span of CRT and LCD monitors, contrary to popular belief (they only prevent burn-in). It is better to let the monitor be turned off by the Windows energy saving settings. - Permissions
- JkDefrag needs “full control” permissions to all files and disks that it must defragment/optimize. On a default Windows system the “administrator” userid has full permissions to all files and disks. Users can also run JkDefrag, but then it can only defragment/optimize the files and disks for which the user has “full control”.
Note: On Vista right-click the JkDefrag program and select “run as administrator”. - Stopping
- All versions of JkDefrag can be stopped safely at any time, there is no risk of losing data or corrupting your disk. You can use all the usual ways to stop a Windows program, such as pressing ALT-F4, clicking the ‘x’ in the top-right corner, via the pull-down menu in the taskbar, or by killing the program via the task manager or another utility. The commandline program can be stopped the same way, plus by pressing CTRL-C, or BREAK. It may take a bit of time for the program to actually stop, JkDefrag will finish the current file in the background.
- Logfile
- JkDefrag writes all messages to a logfile called “JkDefrag.log”, or “JkDefragCmd.log”, or “JkDefragScreenSaver.log”, depending on which version you are using. You can inspect the logfile if you want, it’s a flat-text file. The logfile is automatically cleared when the program starts, it does not grow to infinity.
Tip: you can use environment variables in the name of the logfile, for example “-l %COMPUTERNAME%.log”.
The Windows version of JkDefrag shows a high-detail map of the harddisk, refreshed 3 times per second. Bottom-left of the window is the beginning of the harddisk. The colors used are:
- Black: empty
- Green: regular files, unfragmented
- Dark green: spacehogs, unfragmented
- Yellow: fragmented
- Red: unmovable
- White: busy
- Pink: MFT reserved zone (NTFS only)
- Gray: in use by unknown data

Snapshot of JkDefrag in action. The program is completely automatic,
there are no buttons and no pull-down menu’s.

Tip: Reboot before running JkDefrag. This will release files that are in use, so they can be defragmented. You can also run JkDefrag in Windows safe mode (press F8 while booting) to defrag even more files.
Tip: Stop your real time virus scanner before running JkDefrag. Virus scanners check all disk activity, making defragmentation and optimization very slow.
Tip: Move the swap file to another volume, reboot, defragment, and move the swap file back. If you don’t have a second volume then temporarily make the swap file small, for example 100Mb.
Tip: If an application (for example a database) prevents certain files from being defragmented then stop the application, run JkDefrag for the particular data directory only, and restart the application.
Tip: Package unused files with a packager such as 7-zip . The packagefile not only takes less harddisk space, but will also defragment and optimize much faster than the individual files. Note: This does not apply to Windows NTFS compression, which will actually make defragmentation and optimization a lot slower.
Tip: Buy the biggest harddisk you can afford. Investing in a bigger harddisk gives more speed-per-dollar than investing in a faster CPU or more memory.
Tip: The first partition on a harddisk is significantly faster than other partitions. Try to use other partitions only for “SpaceHog” data (see “What are SpaceHogs?”).
Tip: If you have 2 physical harddisks (of the same speed), then place the pagefile on the first partition of the second harddisk.
How it works
JkDefrag is based on the standard defragmentation API by Microsoft, a system library that is included in Windows 2000, 2003, XP, Vista, and 2008. Most defragmenters are based on this API, including the free defragmenter that comes with Windows and many commercial defragmenters. Basically all JkDefrag does is send “move this file to that location” commands to the API. JkDefrag does not modify the disk by itself, and is therefore extremely solid.
Defragmentation and optimizing will not only make a harddisk faster, but also lengthen it’s life span. The disk will have less work to do and therefore have less wear and tear. Secondly, the sorting optimization strategies (see the “-a” option) will refresh all the magnetic data on your harddisk. However, defragmenting and optimizing is work, so excessive defragmenting and optimizing can actually cause more wear and tear than it prevents. JkDefrag is therefore set for “fast” optimization by default, intended to be used on a daily basis. The other optimizations should only be used occasionally.
- Phase 1: Analyze
- JkDefrag has to scan all the files on the disk to determine if they are fragmented and where they are. A second step inside this phase will apply the exclude masks and determine which files are SpaceHogs.
- Phase 2: Defragment
- All fragmented files are defragmented, simply by moving them to the first gap on the disk that is big enough. If there is no gap big enough then the defragmenter will reduce the number of fragments in the file by moving as much of the file as possible into the largest gaps available.
- Phase 3: Optimize
-
- On most harddisks the beginning of the harddisk is considerably faster than the end, sometimes by as much as 200 percent! See the link to “HD Tune” in the “See Also” chapter for a nice little free program to measure your disk. The default JkDefrag optimization strategy therefore moves all files to the beginning of the volume. It is intended for daily use and will simply fill gaps with files from above, very quick and with very little data movement.
- JkDefrag classifies files into 3 zones: directories (zone 1), regular files (zone 2), and SpaceHogs (zone 3). Directories are perhaps the most accessed data on disk, so zone 1 is placed at the beginning of the harddisk. After the directories comes a free area (see below), then zone 2 with regular files, another free area, and then zone 3 with SpaceHogs (less important files that take up a lot of space). The beginning and end of the zones is determined automatically, see the “-f” option.
- A running computer will create and delete temporary files like there is no tomorrow. If the harddisk were completely optimized then the only place for new temporary files would be behind all the other data. Which is rather slow. So JkDefrag maintains a free space of 1% of the total disk space between zone 1 (directories) and zone 2 (regular files), and between zone 2 and zone 3 (SpaceHogs).
- Sorting the files on your disk can give you even more speed. There are several sorting strategies to choose from (see the “-a” options). These are all very slow and intended for occasional use only.
- Windows reserves a percentage of the disk for the MFT (Master File Table), but can place normal files there if the rest of the disk is full. The files will remain there, even when there is enough space again. JkDefrag looks for files in the MFT reserved space and moves them to normal diskspace, making the reserved space available again for the MFT.
When JkDefrag is running you will see lot’s of messages zipping by showing you exactly what is happening. The messages are also stored in the logfile (“JkDefrag.log” or “JkDefragCmd.log”) for later inspection. The logfile may also contain warning messages, for example when a file could not be moved. This is normal, no need to worry. Windows has many system files that cannot be moved while Windows is running.
Commandline
JkDefrag is completely automatic.
|
For example: | JkDefrag.exe -a 7 -d 2 -q c: d: | |||
-a N | The action to perform. N is a number from 1 to 11, default is 3: 1 = Analyze, do not defragment and do not optimize. 2 = Defragment only, do not optimize. 3 = Defragment and fast optimize [recommended]. 5 = Force together. 6 = Move to end of disk. 7 = Optimize by sorting all files by name (folder + filename). 8 = Optimize by sorting all files by size (smallest first). 9 = Optimize by sorting all files by last access (newest first). 10 = Optimize by sorting all files by last change (oldest first). 11 = Optimize by sorting all files by creation time (oldest first). |
|||
-e “mask” | Exclude files and/or directories that match the mask. The items will not be defragmented and will not be moved. Use wildcards ‘*’ and ‘?’ in the mask to match a set of files or directories. If the mask contains a space then it must be enclosed in double-quotes. Some examples:
|
|||
-u “mask” | Files that match a mask will be moved to the SpaceHogs area. The program has a built-in list for all files bigger than 50 megabytes, files not accessed in the last month, archives, files in the recycle bin, service pack files, and some others. Disable this list by specifying the special mask “DisableDefaults”. Use wildcards ‘*’ and ‘?’ in the mask to match a set of files or directories. If the mask contains a space then it must be enclosed in double-quotes. Some examples:
|
|||
-s N | Slow down to N percent (1…100) of normal speed. Default is 100. | |||
-f N | Set the size of the free spaces to N percent (0…100) of the size of the volume. The free spaces are room on disk for temporary files. There are 2 free spaces, between the 3 zones (directories, regular files, SpaceHogs). Default is 1% (per free space). | |||
-d N | Select a debug level, controlling the messages that will be written to the logfile. The number N is a value from 0 to 6, default is 1: 0 = Fatal errors. 1 = Warning messages [default]. 2 = General progress messages. 3 = Detailed progress messages. 4 = Detailed file information. 5 = Detailed gap-filling messages. 6 = Detailed gap-finding messages. |
|||
-l “filename” | Specify a filename for the logfile. Default is “JkDefrag.log” and “JkDefragCmd.log”. Specify empty string “” (two double-quotes) to disable the logfile. | |||
-h | [commandline version only] Show a short help text. | |||
-help | [commandline version only] Show a short help text. | |||
–help | [commandline version only] Show a short help text. | |||
/? | [commandline version only] Show a short help text. | |||
-q | [windows version only] Quit the program when it has finished. | |||
items | The items to be defragmented and optimized, such as a file, directory, disk, mount point, or volume, including removable media such as floppies, USB disks, memory sticks, and other volumes that behave like a harddisk. Wildcards ‘*’ and ‘?’ are allowed to select a set of files. If the item contains a space then it must be enclosed in double-quotes. Some examples:
|
- Fast optimization
- This optimization strategy is designed for every day use. It moves a minimum of data on the harddisk and finishes very quickly, but will not fill all the gaps on the disk. The strategy scans for gaps on the disk and fills them with files from above.
- Sorted optimization
- All the sorting optimizations WILL CREATE FRAGMENTS. This is by design, it is not a bug. For more info see the Frequently Asked Questions.
These sorting optimizations are for incidental use once in a while. They take a lot of running time and data movement because they rewrite all the data on the disk. The strategies vacate a small area on disk and then fill it up again with the files in the selected order.- Sort by name: very good for fast program starting. The files used by a particular program will be very close together on disk.
- Sort by size: placing all the small files together at the beginning of the disk will dramatically reduce the average file seek time.
- Sort by last access: files that have not been accessed in a while are probably unimportant and are best sorted to the back.
- Sort by last change: placing files together that change a lot (for example databases and log files) will speed up regular operation of the system.
- Sort by creation time: The oldest files on the disk are likely to be important system files, for example used when Windows is booting.
Note: If you want to sort by last access time then first make sure your virus scanner (and other programs that scan all files on disk) do not change that time.
- Force together
- Intended for partition resizing. All movable files are moved to the beginning of the disk, even if it means fragmenting them to fill gaps that cannot be filled otherwise.
- Move to end of disk
- Move all the files to the end of the disk, making more room at the beginning of the disk. Intended for big and rarely used files such as log files, backup archives, installation files, and such.
Frequently asked questions
I have set up a forum for JkDefrag, a place where you can ask questions, give feedback about features you would like, share your experiences, share code that uses the defragger library, and other things about JkDefrag.
![]()
|
Known problems
|