错误:文件路径太长 [英] Error: File Path is Too Long
问题描述
我想使用C#中的各种文件的功能,如 File.GetLastWriteTime
上放置在路径大于在Windows上最大允许路径7即:该文件,复制命令260.它给我的长路径名称的错误。在MSDN上支持我,他们问的路径之前,使用 \\ \?
。我也一样,但我仍然得到了同样的错误,现在看来,这不作任何改变。下面是我的代码。请让我知道如果我使用它正确,或者我需要添加任何东西:
这些所有的lib我使用的代码是有其他的事情也:
i am trying to use the various file functions in C# like File.GetLastWriteTime
, copy command on the file placed at the path greater than maximum allowed path on windows 7 i.e 260. Its giving me an error on long path name. On MSDN support i they have asked to use the \\?\
before the path. I did the same but still i got the same error, it seems it doesn't make any change. Below is my code. Please let me know if i am using it correct or i need to add any thing:
These all lib i am using as the code is having other things also:
下面是相应的代码:
filesToBeCopied = Directory.GetFiles(path,"*",SearchOption.AllDirectories);
for (int j = 0; j < filesToBeCopied.Length; j++)
{
try
{
String filepath = @"\\?\" + filesToBeCopied[j];
File.GetLastWriteTime(filepath);
}
catch (Exception ex)
{
MessageBox.Show("Error Inside the single file iteration for the path:" +
filesToBeCopied[j] + " . The exception is :" + ex.Message);
}
}
其中,作为路径是在Windows的文件夹机器开始驱动器号。为前: D:\abc\bcd\cd\cdc\dc\ ..........
推荐答案
下面是至少您的要求的复制部分的解决方案(谢谢你的pinvoke.net ):
Here's a solution for at least the copying portion of your request (thank you pinvoke.net):
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
static extern bool CopyFile(string lpExistingFileName, string lpNewFileName, bool bFailIfExists);
然后到实际拷贝文件:
And then to actually copy your file:
// Don't forget the '\\?\' for long paths
string reallyLongPath = @"\\?\d:\abc\bcd\cd\cdc\dc\..........";
string destination = @"C:\some\other\path\filename.txt";
CopyFile(reallyLongPath , destination, false);
这篇关于错误:文件路径太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!