Say I have the following path, which we will call the "base":
C:\my\dir
and these two other paths, which we will call paths "A" and "B" respectively:
C:\my\dir\is\a\child
C:\not\my\dir
Obviously, the base must be a directory for this to make any sense. Path A is inside the base at some arbitrary depth, and Path B is not inside base at all. Paths A and B could be files or directories; it really doesn't matter.
How can I detect that Path A is inside base and Path B is not? Preferably, we could avoid directly messing with the strings to do this.
Edit:
The case of the following path has come to my attention:
C:\my\dir2\child
At the moment, the proposed solutions all result in a false positive in this case, but the solution should be able to distinguish. I think this kind of thing is why I was concerned about doing this via string manipulation/comparison directly. What would be the most effective way of dealing with this?
Additionally, I don't want to make any assumptions about whether the base path does or does not contain a trailing directory separator.