MyDefrag (free) may be the most and least flexible defragmentation tool I have used. The most flexible, in that everything it does can be determined by the user to a very fine degree. The least, because all of this must be determined before you start it off. Let me explain.
Most Windows utilities follow the same steps: Start up, give you a bunch of options and settings to tweak, and then run in accordance with them. You can see all, or most, of your choices in the form of buttons, checkboxes, and so forth. MyDefrag is entirely script driven. Your only choice when the program is running is to pause it or cancel it. You must decide, before launching, exactly what you want it to do. Want it to optimize all your disks? Run one script. Want it to move all your old spreadsheets to the end of the hard disk (where access is slower) and your startup programs to the front (where access is faster)? Run another script. Want to change how MyDefrag optimizes? Change a script. Want to optimize just your C and D drive? Change... well, you get the idea.
The GUI for MyDefrag is basically just a monitor to the ongoing process, with a simple screen showing colored dots representing fragmented files, blank areas, and so on. The real "soul" of the program is the scripts, which are plain text files with a "MyD" extension. To run MyDefrag, you actually just double-click on a script.
MyDefrag's scripting language is more of a very, very, advanced series of command line parameters, and does not include any kind of looping or decision-making constructs. Offhand, I can't think of why I'd want them, but some people might. You can specify things to a freakish level of detail, such as defragging only movie files over 50 meg which haven't been accessed since last year. You can cluster files into "zones," deciding which file types will be placed at the front of the disk and which further out. You can create gaps on the disk (blank spaces with no files) where you want them, useful if you plan to partition the disk or want to leave space in a "zone" for future file growth.
MyDefrag has sparse, but functional, documentation. It assumes you're comfortable with scripting languages and programming concepts, and can fire up a text editor, such as Notepad, to edit a script without handholding or walkthroughs. It documents the language (including the formal grammar), and it gives you plenty of examples to mimic and poke at--if you need more than this, you really aren't the target audience for MyDefrag.
MyDefrag uses the Windows defragmentation API, so your files are at minimal risk. As with any powerful utility, you can shoot yourself in the foot--but there's no "Delete File" command and thus no chance of destroying data due to a scripting error. At worst, you will shuffle files to the least optimal places they can be, causing disk access to slow down.
Note: It's a very good idea to prowl your disk for large directories full of junk files, perhaps with a program such as SpaceSniffer, before running a defragger. There's no point in choking MyDefrag moving files you don't need. There are also a handful of known bugs and issues documented at the developer's site.