简体   繁体   English

前缀“\\\\?\\”不适用于处理长路径

[英]Prepending “\\?\” doesn't work for handling long paths

I'm trying to find a workaround for the Windows character limitation that doesn't allow a file to be copied if its name is >= 260 characters. 我正在尝试找到Windows字符限制的解决方法,如果文件的名称> = 260个字符,则不允许复制文件。 According to this MSDN article , if \\\\?\\ is prepended to the file name, this will circumvent the filename length restriction. 根据这篇MSDN文章 ,如果文件名前面有\\\\?\\ ,这将绕过文件名长度限制。

I tried this test: 我试过这个测试:

string source = "\\\\?\\C:\\Users\\xxxx\\Documents\\Visual Studio 2013\\Projects\\PDFConverterTester\\PDFConverterTester_BatchGUI\\bin\\Debug\\folder1\\a.txt";
string dest= "\\\\?\\C:\\Users\\xxxx\\Documents\\Visual Studio 2013\\Projects\\PDFConverterTester\\PDFConverterTester_BatchGUI\\bin\\Debug\\folder2\\a.txt";            
System.IO.File.Copy(source, dest);

But this threw an exception: 但这引发了一个例外:

Illegal characters in path.

Should I be applying this prefix in a different way? 我应该以不同的方式应用此前缀吗?

Edit: My company's IT policy will not allow me to install any new software without a lengthy review process, meaning that I can't update to 4.6.2. 编辑:我公司的IT政策不允许我在没有冗长的审核过程的情况下安装任何新软件,这意味着我无法更新到4.6.2。 so I'm trying to figure out how to resolve this with Windows API calls from my existing .NET 4.5 installation of Visual Studio. 所以我试图弄清楚如何使用我现有的Visual Studio .NET 4.5安装中的Windows API调用来解决这个问题。

To enable long path support you either need to be targetting .Net Framework 4.6.2 (or newer) or you need to tell your app that it can support long filenames. 要启用长路径支持,您需要定位.Net Framework 4.6.2(或更新版本),或者您需要告诉您的应用它可以支持长文件名。 To do that, add this to your app.config: 为此,请将其添加到app.config:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
</runtime>

Further reading can be done here . 可以在这里进一步阅读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM