如何强制最大路径长度超过260个字符 [英] How do I force a maximum pathlength with more than 260 characters

查看:190
本文介绍了如何强制最大路径长度超过260个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有保存问题。我需要图像哪条路径长于260个字符(可悲的是它们必须很长。不是我的想法!)



我在这里找到了这个:

[ ^ ]



我试过了\\ ?\但它不起作用。



我的路径是:\\?\ D:\ Temp1 \ Data \

在这种情况下,Visual Studio说有一个未知的转义序列。



然后我试了@\\?\ D :\ Temp1 \Data

Visual Studio说有一个不允许的标志。我想这是?



当我在没有\\?\的情况下尝试它时,有一个Windows例外,它说Path只允许260个字符。



我做了什么错误?



我希望你能帮助我。



祝你好运

Richard



我尝试过什么:



这些链接:

https://blogs.msdn.microsoft.com/bclteam/2007/03/ 26 / long-path-in-net-part-2-of-3-long-path-workarounds-kim-hamilton /



https:// msdn。 microsoft.com/en-us/library/aa365247.aspx

Hello everyone,

I have a problem with saving. I need to images which path's are longer than the 260 characters (Sadly they have to be this long. Not my idea!)

I found this one here:
[^]

I tried the \\?\ but it didn't work.

My path is: "\\?\D:\Temp1\Data\"
In this case Visual Studio says that there is an unknown escape sequence.

Then i tried @"\\?\D:\Temp1\Data"
Visual Studio says that there is a sign which is not allowed. I guess it is the "?"

And when I try it without the \\?\ there is the windows exception which says that the Path only allows 260 characters.

What mistake/s did i do?

I hope you can help me.

Best regards
Richard

What I have tried:

These links:
https://blogs.msdn.microsoft.com/bclteam/2007/03/26/long-paths-in-net-part-2-of-3-long-path-workarounds-kim-hamilton/

https://msdn.microsoft.com/en-us/library/aa365247.aspx

推荐答案

你好Evosoul04,



可悲的是我不能为你的问题提供真正的帮助。但至少我试图按照您链接的博客文章中的步骤进行操作。我将代码复制到一个小测试项目中。但是我观察到了和你一样的行为 - 它不起作用(系统无法找到指定的路径),但我认为它根据以下内容完成了所有操作:命名文件,路径和命名空间(Windows) [ ^ ]

所以至少你可以说:其他人有同样的问题;) - 在我看来我们错过了一些重要的信息来实现这一点(或微软改变了两者之间的行为 - 谁知道?)



来自奥地利的问候

Johannes
Hi Evosoul04,

Sadly I can offer no real help for your problem. But at least I tried to follow the steps from your linked blog article. I copied the code to a little test project. But I observed the same behavior like you - it didn't work (System can not find the path specified), But I think it did everything correct according to: Naming Files, Paths, and Namespaces (Windows)[^]
So at least you can say: others had the same Problem ;) - It seems to me that we miss some important information here to get this working (or Microsoft changed the behavior in between -who knows?)

Greetings from Austria
Johannes


我使用了您提供的链接中的代码,它按预期工作。请编辑您的问题并显示您正在使用的确切代码,以便我们看到有什么不同。





以下代码有效:

I used the code in the link you provided and it worked as expected. Please edit your question and show the exact code you are using so we can see what is different.

[edit]
The following code works:
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool DeleteFile(string lpFileName);

public static void Delete(string fileName)
{
    string formattedName = @"\\?\D:\Temp\" + fileName;
    DeleteFile(formattedName);
}



[/ edit]


[/edit]


这篇关于如何强制最大路径长度超过260个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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