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);
string path1 = "C:\test"; string path2 = "C:\test\abc"; var root = Path.GetFullPath(path1); var secondDir = Path.GetFullPath(path2 + Path.AltDirectorySeparatorChar); if (!secondDir.StartsWith(root)) { }
Path.GetFullPath works great with paths, like: C:\test\..\forbidden\
Path.GetFullPath
C:\test\..\forbidden\