开发者

How to find out if path meets certain parent?

So we have a parent like somepath/** so if any one sends to us somepath/myfolder/file we would receive true and if we would receive someotherpath/ we would get false. So how to find out if a p开发者_StackOverflow社区ath meets certain parent?


You need to normalize both paths, then you do a simple substring comparison to see if your path in question starts with the normalized reference path.

Normalizing includes adding the current working directory to a relative path, case normalization if your file system is case-insensitive, probably resolving symbolic links and maybe even testing for hard links. If you want to allow the file itself to be a symbolic link you have to extract the path portion prior to normalization.

I've done this in linux using the realpath() function and it works very well, even if the reference path contains symlinks. Don't know how to do it with boost, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜