PathEx.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.IO;
  2. namespace BansheeEngine
  3. {
  4. public static class PathEx
  5. {
  6. public static bool Compare(string a, string b)
  7. {
  8. return Path.GetFullPath(a) == Path.GetFullPath(b);
  9. }
  10. public static bool IsPartOf(string path, string parent)
  11. {
  12. return Path.GetFullPath(path).StartsWith(Path.GetFullPath(parent));
  13. }
  14. public static string GetTail(string path)
  15. {
  16. if (string.IsNullOrEmpty(path))
  17. return "";
  18. if (path[path.Length - 1] == Path.DirectorySeparatorChar ||
  19. path[path.Length - 1] == Path.AltDirectorySeparatorChar)
  20. {
  21. return Path.GetDirectoryName(path);
  22. }
  23. return Path.GetFileName(path);
  24. }
  25. public static string GetParent(string path)
  26. {
  27. string tail = GetTail(path);
  28. return path.Remove(path.Length - tail.Length);
  29. }
  30. public static bool IsValidFileName(string name)
  31. {
  32. return !string.IsNullOrWhiteSpace(name) &&
  33. name.IndexOfAny(Path.GetInvalidFileNameChars()) < 0;
  34. }
  35. }
  36. }