简体   繁体   English

Windows路径的长度超过260个字符

[英]Windows path with a length of more than 260 characters

I need to copy files that have a path with a length greater than 260 characters. 我需要复制路径长度大于260个字符的文件。

If I understood correctly, File.Copy doesn't allow to do that. 如果我正确理解,则File.Copy不允许这样做。 I have to use Win32.CopyFile and add \\\\?\\ before the path. 我必须使用Win32.CopyFile并在路径之前添加\\\\?\\

But if I try to access to \\\\?\\my_server\\my_path\\my_file , I get the error 0x03 (path not found). 但是,如果尝试访问\\\\?\\my_server\\my_path\\my_file ,则会收到错误0x03(找不到路径)。 However, the same link in the Explorer works fine. 但是,资源管理器中的相同链接可以正常工作。

Files are stored in DFS file structures. 文件存储在DFS文件结构中。 Is it important? 这非常重要吗?

string src  = @"\\?\my_server\my_folder\my_file.ext";

if (Kernel32.CopyFile(src, f2c.getDest, true))
{
    Console.WriteLine("[SUCCESS] Copie du fichier {0} vers {1}", src, f2c.getDest);
    list_updSQL.Add(String.Format(@"UPDATE dbo.Fichier SET NOM_FICHIER_COPIE = '{0}' WHERE HASH_FICHIER ='{1}' ;", src, f2c.getHash));
}
else
{   
    Console.WriteLine("[FAILED][ERROR {0}] Copie du fichier {1} vers {2}", Kernel32.GetLastError().ToString(), src, f2c.getDest);
}

/* ----- */

[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern bool CopyFile(string lpExistingFileName, string lpNewFileName, bool bFailIfExists);

[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern UInt32 GetLastError();

You need to specify the correct syntax for UNC paths. 您需要为UNC路径指定正确的语法。

See MSDN . 参见MSDN

From MSDN: 从MSDN:

The "\\\\?\\" prefix can also be used with paths constructed according to the universal naming convention (UNC). “ \\\\?\\”前缀也可以与根据通用命名约定(UNC)构造的路径一起使用。 To specify such a path using UNC, use the "\\\\?\\UNC\\" prefix. 要使用UNC指定这样的路径,请使用“ \\\\?\\ UNC \\”前缀。 For example, "\\\\?\\UNC\\server\\share", where "server" is the name of the computer and "share" is the name of the shared folder. 例如,“ \\\\?\\ UNC \\ server \\ share”,其中“ server”是计算机的名称,“ share”是共享文件夹的名称。

In your example above, you probably want: 在上面的示例中,您可能需要:

string src = @"\\\\?\\UNC\\my_server\\my_folder\\my_file.ext";

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

相关问题 如何获取路径超过 260 个字符的文件的长度? - How do I get the length of a file with a path longer than 260 characters? 该文件解析为太长的路径。 最大长度为260个字符 - The file resolves to a path that is too long. The maximum length is 260 characters 如何强制使用超过260个字符的最大路径长度 - How do I force a maximum pathlength with more than 260 characters 完整路径必须少于 260 个字符 - SSRS - full path must be less than 260 characters - SSRS Windows 7路径太长,无法使用.Net Framework 4.6.2创建260个字符以上的文件 - Windows 7 Path too long to create file above 260 Characters with .Net Framework 4.6.2 字符串长度超过32768个字符时的Azure存储异常 - Azure Storage exception when a string length is more than 32768 characters 在Windows Phone的SQL Server CE中具有4000个以上字符的NTEXT - NTEXT with more than 4000 characters in SQL Server CE in Windows Phone 获取超过 260 个字符的过长文件路径的安全信息:C# - Get Security Information of a too long file path above 260 characters: C# DER长度超过4个字节? - DER length is more than 4 bytes? 正则表达式匹配超过4个字符 - Regex Match more than 4 characters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM