internal static bool IsEqualOrSubdirectory(string dir, string subdir) {
if (String.IsNullOrEmpty(dir))
return true;
if (String.IsNullOrEmpty(subdir))
return false;
//
// Compare up to but not including trailing backslash
//
int lDir = dir.Length;
if (dir[lDir - 1] == '\\') {
lDir -= 1;
}
int lSubdir = subdir.Length;
if (subdir[lSubdir - 1] == '\\') {
lSubdir -= 1;
}
if (lSubdir < lDir)
return false;
if (String.Compare(dir, 0, subdir, 0, lDir, StringComparison.OrdinalIgnoreCase) != 0)
return false;
// Check subdir that character following length of dir is a backslash
if (lSubdir > lDir && subdir[lDir] != '\\')
return false;
return true;
}