Rella
Rella

Reputation: 66945

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 path meets certain parent?

Upvotes: 0

Views: 367

Answers (1)

kiw
kiw

Reputation: 808

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.

Upvotes: 1

Related Questions