/// <summary> /// Deletes the files. /// </summary> /// <param name="files">The files.</param> /// <returns>IEnumerable<KeyValuePair<System.String, System.String>>.</returns> public static IEnumerable<KeyValuePair<string, string>> DeleteFiles(this IEnumerable<string> files) { var errors = new SortedDictionary<string, string>(); foreach (var information in files.AsParallel()) { try { File.Delete(information); } catch (IOException fileIOException) { errors.AddIfNotExists(new KeyValuePair<string, string>(information, fileIOException.Message)); } catch (UnauthorizedAccessException notAuthorizedException) { errors.AddIfNotExists(new KeyValuePair<string, string>(information, notAuthorizedException.Message)); } } return errors.AsEnumerable(); }
/// <summary> /// Deletes the files. /// </summary> /// <param name="files">The files.</param> /// <returns>IEnumerable<KeyValuePair<System.String, System.String>>.</returns> public static IEnumerable <KeyValuePair <string, string> > DeleteFiles(this IEnumerable <string> files) { var errors = new SortedDictionary <string, string>(); Parallel.ForEach(files, (information) => { try { File.Delete(information); } catch (IOException fileIOException) { errors.AddIfNotExists(new KeyValuePair <string, string>(information, fileIOException.Message)); } catch (UnauthorizedAccessException notAuthorizedException) { errors.AddIfNotExists(new KeyValuePair <string, string>(information, notAuthorizedException.Message)); } }); return(errors.AsEnumerable()); }