![](/img/trans.png)
[英]How do I get the length of a file with a path longer than 260 characters?
[英]Windows path with a length of more than 260 characters
我需要复制路径长度大于260个字符的文件。
如果我正确理解,则File.Copy
不允许这样做。 我必须使用Win32.CopyFile
并在路径之前添加\\\\?\\
。
但是,如果尝试访问\\\\?\\my_server\\my_path\\my_file
,则会收到错误0x03(找不到路径)。 但是,资源管理器中的相同链接可以正常工作。
文件存储在DFS文件结构中。 这非常重要吗?
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();
您需要为UNC路径指定正确的语法。
参见MSDN 。
从MSDN:
“ \\\\?\\”前缀也可以与根据通用命名约定(UNC)构造的路径一起使用。 要使用UNC指定这样的路径,请使用“ \\\\?\\ UNC \\”前缀。 例如,“ \\\\?\\ UNC \\ server \\ share”,其中“ server”是计算机的名称,“ share”是共享文件夹的名称。
在上面的示例中,您可能需要:
string src = @"\\\\?\\UNC\\my_server\\my_folder\\my_file.ext";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.