C# 尝试将文件从一个目录复制到另一个目录时发生FileNotFoundException
我在“C:\ABC\Temp”中有一些文件(.txt、word、excel文件),我想将所有.txt文件移到“C:\ABC\Text”中,但我得到了一个C# 尝试将文件从一个目录复制到另一个目录时发生FileNotFoundException,c#,.net,io,filenotfoundexception,C#,.net,Io,Filenotfoundexception,我在“C:\ABC\Temp”中有一些文件(.txt、word、excel文件),我想将所有.txt文件移到“C:\ABC\Text”中,但我得到了一个FileNotFoundException 请查找附件代码 static void Main() { string sp = @"C:/ABC/Temp"; string dp = @"C:/ABC/TextFiles"; string[] fileList=Directory.GetFiles(sp); for
FileNotFoundException
请查找附件代码
static void Main()
{
string sp = @"C:/ABC/Temp";
string dp = @"C:/ABC/TextFiles";
string[] fileList=Directory.GetFiles(sp);
foreach(string file in fileList)
{
if (file.EndsWith(".txt"))
{
File.Move(sp,dp);
}
}
}
}
}您正试图使用
文件移动整个目录。移动
您还必须指定文件名:
File.Move(file, Path.Combine(dp, Path.GetFileName(file)));
未处理的异常:System.IO.FileNotFoundException:找不到文件“C:\AB C\Temp\123.txt.txt”。在C:\Users\neerajkumar.p\AppData\Local\Temporary p projects\demonio\Class1.cs中demonio.Class1.Main()的System.IO.IO.IO.IO.Error.WinIOError(Int32 errorCode,String maybeFullPath)处的InternalMove(String sourceFileName,String destFileName,Bo olean checkHost)处按任意键继续。我看不到乔尼的密码。不知道为什么?你能帮我贴一下吗@Grant Winney