【发布时间】:2011-10-25 16:39:43
【问题描述】:
只是一个简单的问题(我希望): 当我使用 File.Move 时,它给了我一个错误:
System.IO.DirectoryNotFoundException was unhandled by user code
Message=Could not find a part of the path.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.__Error.WinIOError()
at System.IO.File.Move(String sourceFileName, String destFileName)
at Portal_2_Level_Installer.Form1.WorkMagic(String FileLocation) in C:\Users\Yoshie\Local Settings\Documents\Visual Studio 2010\Projects\Portal 2 Level Installer\Portal 2 Level Installer\Form1.cs:line 265
InnerException:
我的代码:
File.Move(FileLocation, destinationPath);
以及变量的内容:
destinationPath="c:/program files (x86)/steam\\steamapps\\common\\portal 2\\Test\\Test.docx"
FileLocation="C:\\Users\\Yoshie\\Local Settings\\Documents\\Test.docx"
谢谢! 编辑:我现在真的觉得自己像个白痴。我没有意识到目标文件夹必须存在!我愚蠢地假设如果目标文件夹不存在,它会自动创建。很抱歉浪费您的时间,但还是感谢您的回答! (我现在知道我可以使用 @ 来停止转义,所以很高兴知道) 无论如何,谢谢,再次抱歉!
【问题讨论】:
-
你检查了 destinationPath 吗?它有正斜杠和反斜杠!重新检查!
-
c:/program files (x86)/应该是 c:\\program files (x86)\\ -
@Anton,不,他们不是。至少以 c# 方式。
-
+1 提供一个清晰的例子并承认你的错误。如果更多的程序员能够承认自己的错误,我们的行业就会变得更好:)