public static void DeleteFiles(this ICakeContext cakeContext, DeleteHelpersConfig config) { FilePathCollection files = cakeContext.GetFiles(config.FullDirectory.ToString()); List <FilePath> orderedFiles = files.OrderBy(f => System.IO.File.GetCreationTime(f.ToString())).ToList(); while (orderedFiles.Count > config.NumberOfFilesToKeep) { FilePath file = orderedFiles[0]; cakeContext.Information($"Deleting '{file}'"); if (config.DryRun == false) { cakeContext.DeleteFile(file); } orderedFiles.RemoveAt(0); } }