| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System.IO;
- namespace BansheeEngine
- {
- public static class PathEx
- {
- public static bool Compare(string a, string b)
- {
- return Path.GetFullPath(a) == Path.GetFullPath(b);
- }
- public static bool IsPartOf(string path, string parent)
- {
- return Path.GetFullPath(path).StartsWith(Path.GetFullPath(parent));
- }
- public static string GetTail(string path)
- {
- if (string.IsNullOrEmpty(path))
- return "";
- if (path[path.Length - 1] == Path.DirectorySeparatorChar ||
- path[path.Length - 1] == Path.AltDirectorySeparatorChar)
- {
- return Path.GetDirectoryName(path);
- }
- return Path.GetFileName(path);
- }
- public static string GetParent(string path)
- {
- string tail = GetTail(path);
- return path.Remove(path.Length - tail.Length);
- }
- public static bool IsValidFileName(string name)
- {
- return !string.IsNullOrWhiteSpace(name) &&
- name.IndexOfAny(Path.GetInvalidFileNameChars()) < 0;
- }
- }
- }
|