第二个路径片段不能是驱动器或UNC名称-创建子目录错误 [英] Second path fragment must not be a drive or UNC name - Create Subdirectory Error

查看:1826
本文介绍了第二个路径片段不能是驱动器或UNC名称-创建子目录错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码第三行出现异常第二个路径段不得为驱动器或UNC名称"

I have an exception in the third line ofthis code "Second path fragment must not be a drive or UNC name"

DirectoryInfo labdi = new DirectoryInfo(Back.mainfolderpath + @"\news\l");
DirectoryInfo tld = new DirectoryInfo(labdi.FullName + @"\" + NorA.sn.labl[i]);
tld = labdi.CreateSubdirectory(labdi.FullName + @"\" + NorA.sn.labl[i] + @"\");

网络上没有有用的方法. 谢谢.:!

There is no useful way on the web. Thank You.:!

推荐答案

我今天遇到了这个问题,最后找到了它.

I ran into this one today and finally tracked it down.

该异常试图告诉您,当DirectoryInfo将路径作为参数(例如,CreateSubdirectory或GetFiles)时,如果path参数包含Root并抛出此难以捉摸的异常,它将拒绝.

The exception is trying to tell you that when a DirectoryInfo takes a path as an argument (e.g., CreateSubdirectory or GetFiles), it will object if the path argument contains the Root and throw this elusive exception.

因此包含"C:\"或"D:\"等的路径参数不起作用.有了这种上下文,异常消息实际上就有意义了.

So path arguments that contain "C:\" or "D:\" etc do not work. Armed with this context, the exception message actually makes a bit of sense.

在您的代码中,您使用的是FullName属性,并且此字符串包含"C:\"或任何根.

In your code, you were using the FullName property and this string contains "C:\" or whatever the root is.

鉴于这个问题的年龄,我应该添加c#、. NET 4.5,VS2013.

Given the age of the question, I should add c#, .NET 4.5, VS2013.

这篇关于第二个路径片段不能是驱动器或UNC名称-创建子目录错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆