System.IOUtils.TDirectory.GetParent odd behavior?

后端 未结 1 1649
借酒劲吻你
借酒劲吻你 2021-01-20 14:54

The result of GetParent(\'c:\\1\\2\\\') is \'c:\\1\\2\'.

And the result of GetParent(\'c:\\1\\2\') is \'c:\\1\'.<

相关标签:
1条回答
  • 2021-01-20 15:15

    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".

    0 讨论(0)
提交回复
热议问题