gpt4 book ai didi

c# - 如何获取根目录

转载 作者:太空宇宙 更新时间:2023-11-03 17:17:27 25 4
gpt4 key购买 nike

我有一个文件路径为

D:\Accurev\PPF6-AvailableToUse_Test_4_4\eBizSol_App\Source\xyz.txt

如果我这样做

Path.GetDirectoryName(fileName)

我明白了

D:\Accurev\PPF6-AvailableToUse_Test_4_4\eBizSol_App\Source

但我只想获取根目录,即 "D:\\"

我怎样才能得到它?

N.B.~有没有可能不进行字符串拆分?

最佳答案

使用Path.GetPathRoot框架提供的方法

Gets the root directory information of the specified path

对于您的情况,您可以使用:

string rootPath = Path.GetPathRoot(filename);

关于c# - 如何获取根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17357109/

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