You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

56 lines
1.6 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using Alphaleonis.Win32.Filesystem;
  4. namespace NTFSSecurity
  5. {
  6. public static class Extensions
  7. {
  8. public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
  9. {
  10. if (source == null) { throw new ArgumentException(); }
  11. if (action == null) { throw new ArgumentException(); }
  12. foreach (T element in source)
  13. {
  14. action(element);
  15. }
  16. }
  17. public static FileSystemInfo GetParent(this FileSystemInfo item)
  18. {
  19. var parentPath = System.IO.Path.GetDirectoryName(item.FullName);
  20. if (File.Exists(parentPath))
  21. {
  22. return new FileInfo(parentPath);
  23. }
  24. else if (Directory.Exists(parentPath))
  25. {
  26. return new DirectoryInfo(parentPath);
  27. }
  28. else
  29. {
  30. throw new System.IO.FileNotFoundException();
  31. }
  32. }
  33. public static System.IO.FileSystemInfo GetParent(this System.IO.FileSystemInfo item)
  34. {
  35. var parentPath = System.IO.Path.GetDirectoryName(item.FullName);
  36. if (File.Exists(parentPath))
  37. {
  38. return new System.IO.FileInfo(parentPath);
  39. }
  40. else if (Directory.Exists(parentPath))
  41. {
  42. return new System.IO.DirectoryInfo(parentPath);
  43. }
  44. else
  45. {
  46. throw new System.IO.FileNotFoundException();
  47. }
  48. }
  49. }
  50. }