Defragging is best left to defragging programs.
C# isn't exactly geared up for making a defrag program due to low level hdd access requirements.
Consider calling the windows defrag program or another piece of 3rd party software to do the defragmentation itself.
How to call processes:
using System.Diagnostics; ... Process myProc; // Start the process. myProc = Process.Start("filename"); //The process does something. ... // Stop the process. myProc.CloseMainWindow();
The filename can be an external executable or any file that has an application associated with it. For example if you used "expenses.doc" in place of "filename", your application would launch MS Word with your expenses.doc loaded.
Also, the myProc.CloseMainWindow() method is used for Window apps. For Console apps use the myProc.Kill(); method instead.