1
Vote

DeleteFiles should use FileInfo methods

description

The FileInfo class exposes an Exists property and a Delete method. The DirectoryInfoExtensions.DeleteFiles method should use these rather than the File.Exists and File.Delete methods, since the path normalization has already been performed.
 
public static void DeleteFiles(this IEnumerable<FileInfo> filesToDelete)
{
if (null == filesToDelete) throw new ArgumentNullException("filesToDelete");
filesToDelete.Where(file => file.Exists).ForEach(file => file.Delete());
}
 
public static void DeleteFiles(this DirectoryInfo directoryInfo, IEnumerable<string> searchPatterns)
{
DeleteFiles(GetFiles(directoryInfo, searchPatterns));
}

comments