/// <summary> /// check if the search item path is a subdirectory of the rootDir /// </summary> /// <param name="rootDir"></param> /// <param name="searchItem"></param> /// <returns></returns> public static bool IsSubdirectory(string rootDir, string searchItem) { var root = new DirectoryPathAbsolute(rootDir); var search = new DirectoryPathAbsolute(searchItem); return search.IsChildDirectoryOf(root); }
/// <summary> /// check if the search item path is a subdirectory of the rootDir /// </summary> /// <param name="rootDir"></param> /// <param name="searchItem"></param> /// <returns></returns> public static bool IsSubdirectory(string rootDir, string searchItem) { if (rootDir.StartsWith("\\")) //network disk? { return searchItem.StartsWith(rootDir, StringComparison.InvariantCultureIgnoreCase); } else { var root = new DirectoryPathAbsolute(rootDir); var search = new DirectoryPathAbsolute(searchItem); return search.IsChildDirectoryOf(root); } }