gpt4 book ai didi

delphi - System.IOUtils.TDirectory.GetParent 奇怪的行为?

转载 作者:行者123 更新时间:2023-12-03 15:51:46 36 4
gpt4 key购买 nike

GetParent('c:\1\2\') 的结果是 'c:\1\2'

GetParent('c:\1\2') 的结果是 'c:\1'

这是正常/预期的行为吗?如果是,其背后的逻辑是什么?

最佳答案

这种行为可能看起来有点奇怪,但这是设计使然。该类以 .net 类 Directory 为模型。 documentation对于 Directory.GetParent 说:

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

关于delphi - System.IOUtils.TDirectory.GetParent 奇怪的行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35429699/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com