gpt4 book ai didi

c# - "Could not find a part of the path"错误信息

转载 作者:可可西里 更新时间:2023-11-01 03:05:27 25 4
gpt4 key购买 nike

我正在用 C# 编程,想从闪存盘复制一个文件夹和子文件夹以启动。

这是我的代码:

private void copyBat()
{
try
{
string source_dir = "E:\\Debug\\VipBat";
string destination_dir = "C:\\Users\\pc\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";

if (!System.IO.Directory.Exists(destination_dir))
{
System.IO.Directory.CreateDirectory(destination_dir);
}

// Create subdirectory structure in destination
foreach (string dir in Directory.GetDirectories(source_dir, "*", System.IO.SearchOption.AllDirectories))
{
Directory.CreateDirectory(destination_dir + dir.Substring(source_dir.Length));
}

foreach (string file_name in Directory.GetFiles(source_dir, "*.*", System.IO.SearchOption.AllDirectories))
{
File.Copy(file_name, destination_dir + file_name.Substring(source_dir.Length), true);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message, "HATA", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}

我得到一个错误:

Could not find a part of the path E:\Debug\VipBat

最佳答案

您尝试访问的路径不存在。

string source_dir = "E:\\Debug\\VipBat\\{0}";

我确定这不是正确的路径。 Debug文件夹直接在E:驱动器在我看来是错误的。我想一定有项目名称文件夹目录存在。

第二件事;什么是 {0}在你的字符串中。我确定它是一个参数占位符,因为文件夹名称不能包含 {0}这样的名字。所以你需要使用 String.Format()替换实际值。

string source_dir = String.Format("E:\\Debug\\VipBat\\{0}",variableName);

但首先检查您尝试访问的路径是否存在。

关于c# - "Could not find a part of the path"错误信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21796687/

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