我有一个与网络上的位置有关的字符串,我需要从这个位置获取2个目录.
字符串可以采用以下格式:
string networkDir = "\\\\networkLocation\\staff\\users\\username";
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我需要该staff文件夹,并可以使用以下逻辑:
string parentDir1 = Path.GetDirectoryName(networkDir);
string parentDir2 = Path.GetPathRoot(Path.GetDirectoryName(networkDir));
Run Code Online (Sandbox Code Playgroud)
但是,如果字符串的格式为:
string networkDir = "\\\\networkLocation\\users\\username";
Run Code Online (Sandbox Code Playgroud)
我只需要该networkLocation部分并parentDir2返回null.
我怎样才能做到这一点?
只是为了澄清:如果根恰好是给定文件夹中的目录2,那么这就是我需要返回的内容
c# ×1