gpt4 book ai didi

c# - File.Move 引起的 System.IO.DirectoryNotFoundException

转载 作者:太空狗 更新时间:2023-10-29 21:41:29 31 4
gpt4 key购买 nike

只是一个简单的问题(我希望):当我使用 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"

谢谢!编辑:我现在真的觉得自己像个白痴。我没有意识到目标文件夹必须存在!我愚蠢地假设如果目标文件夹不存在,它会自动创建。很抱歉浪费您的时间,但还是感谢您的回答! (我现在知道我可以使用 @ 来停止转义,所以很高兴知道)无论如何,谢谢,再次抱歉!

最佳答案

请使用\而不是/以及像 @“路径”一样使用 @。

关于c# - File.Move 引起的 System.IO.DirectoryNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7038505/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com