static void DefragDirectory(string volumeName, string path) { var defragger = new VolumeDefragmenter(volumeName); var files = new DirectoryInfo(path).GetFiles(); int totalDone = 0; int perfectGaps = 0; foreach (var file in files) { if (file.Length == 0) { continue; } if (defragger.DefragFile(file.FullName)) { perfectGaps++; } totalDone++; Console.Title = $"Total done: {totalDone:#,0}, perfect gaps: {perfectGaps:#,0}"; } }
static bool DefragFile(string volumeName, string fileName) { var defragger = new VolumeDefragmenter(volumeName); return(defragger.DefragFile(fileName)); }