“找不到路径的一部分”;错误信息 [英] "Could not find a part of the path" error message

查看:117
本文介绍了“找不到路径的一部分”;错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am programming in c# and want to copy a folder with subfolders from a flash disk to startup.

这是我的代码:

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);
    }
}

我遇到错误:


找不到路径的一部分E:\Debug\VipBat

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


推荐答案

该错误不言自明。您尝试访问的路径不存在。

The error is self explanatory. The path you are trying to access is not present.

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

我确定这不是正确的路径。直接在 E中的 Debug 文件夹:驱动器对我来说似乎是错误的。我猜一定存在项目名称文件夹目录。

I'm sure that this is not the correct path. Debug folder directly in E: drive looks wrong to me. I guess there must be the project name folder directory present.

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

Second thing; what is {0} in your string. I am sure that it is an argument placeholder because folder name cannot contains {0} such name. So you need to use String.Format() to replace the actual value.

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

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

But first check the path existence that you are trying to access.

这篇关于“找不到路径的一部分”;错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆