The result of GetParent(\'c:\\1\\2\\\')
is \'c:\\1\\2\'
.
And the result of GetParent(\'c:\\1\\2\')
is \'c:\\1\'
.<
This behaviour might seem a little odd but it is by design. This class is modelled on the .net class Directory
. The documentation for Directory.GetParent
says:
The string returned by this method consists of all characters in the path up to, but not including, the last DirectorySeparatorChar or AltDirectorySeparatorChar. For example, passing the path "C:\Directory\SubDirectory\test.txt" to GetParent returns "C:\Directory\SubDirectory". Passing "C:\Directory\SubDirectory" returns "C:\Directory". However, passing "C:\Directory\SubDirectory\" returns "C:\Directory\SubDirectory", because the ending directory separator is after "SubDirectory".