//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System.IO; namespace BansheeEngine { /** @addtogroup Utility * @{ */ /// /// Contains helper methods dealing with file and directory paths, extending the functionality provided by /// System.IO.Path. /// public static class PathEx { /// /// Checks if two paths are equal. /// /// First path. /// Second path. /// True if both paths point to the same place. public static bool Compare(string a, string b) { if (string.IsNullOrEmpty(a)) { if (string.IsNullOrEmpty(b)) return true; return false; } else { if (string.IsNullOrEmpty(b)) return false; } return Path.GetFullPath(a) == Path.GetFullPath(b); } /// /// Checks if one path is part of an another path. /// /// Path to check if it's part of . /// Parent that might contain . /// True if contains . public static bool IsPartOf(string path, string parent) { return Path.GetFullPath(path).StartsWith(Path.GetFullPath(parent)); } /// /// Returns the last entry in the path, regardless if that is a directory or a filename. /// /// Path to get the tail of. /// Tail of the path. This might be a directory or a filename. 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.GetFileName(path.Substring(0, path.Length - 1)); } return Path.GetFileName(path); } /// /// Returns the parent of the provided path. /// /// Path to return the parent of. /// Parent of the path. This usually means the folder containing the file or folder in the current path. /// public static string GetParent(string path) { string tail = GetTail(path); return path.Remove(path.Length - tail.Length); } /// /// Checks if the provided name can be used as a file name. /// /// Name to check. /// True if the name can be used as a file name. public static bool IsValidFileName(string name) { return !string.IsNullOrWhiteSpace(name) && name.IndexOfAny(Path.GetInvalidFileNameChars()) < 0; } } /** @} */ }