作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在用 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/
我是一名优秀的程序员,十分优秀!