I have 2 strings - dir1 and dir2, and I need to check if one is sub-directory for other. I tried to go with Contains method:
dir1.contains(dir2);
In my case the path and possible subpath do not contains '..' and never end in '\':
private static bool IsSubpathOf(string path, string subpath) { return (subpath.Equals(path, StringComparison.OrdinalIgnoreCase) || subpath.StartsWith(path + @"\", StringComparison.OrdinalIgnoreCase)); }