How to check if one path is a child of another path?

前端 未结 7 1416
温柔的废话
温柔的废话 2020-12-09 17:57

How to check if one path is a child of another path?
Just checking for substring is not a way to go, because there can items such as . and .., etc

7条回答
  •  囚心锁ツ
    2020-12-09 18:38

    In C# you can do it like this:

    string cp = Path.GetFullPath(childPath);
    string pp = Path.GetFullPath(parentPath);
    
    if(pp.StartsWith(cp))
        return true;
    else
        return false;
    

提交回复
热议问题