简体   繁体   English

如何将checkedListBox中列出的目录复制到另一个目录?

[英]How to copy directory listed in checkedListBox to another directory?

I'm trying to make application which will backup folders before system reinstallation. 我正在尝试制作应用程序,它将在重新安装系统之前备份文件夹。

What I've got now, you can see above. 我现在得到的,你可以在上面看到。 After click on Button2 i've got "Could not find directory 'C:\\Projects\\WindowsFormsApplication2\\WindowsFormsApplication2\\bin\\Debug.Desktop'." 点击Button2后,我找到了“无法找到目录”C:\\ Projects \\ WindowsFormsApplication2 \\ WindowsFormsApplication2 \\ bin \\ Debug.Desktop'。“

It seems that I can't get properly full path to directory. 看来我无法正确获取目录的完整路径。

    public void button1_Click(object sender, EventArgs e)
    {

        string path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
        System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(patg);
        System.IO.FileSystemInfo[] files = di.GetDirectories();
        checkedListBox1.Items.AddRange(files);
    }


    private void button2_Click(object sender, EventArgs e)
    {
            foreach (object itemChecked in checkedListBox1.CheckedItems)
            {
                string P = Path.GetFullPath(itemChecked.ToString());
                DirectoryInfo di = new DirectoryInfo(P);
                FileSystem.CopyDirectory(P, @"P:\");
            }
    }

I expect that user can check boxes from list and then click on Copy(button2) which will copy folder to another location. 我希望用户可以从列表中选中复选框,然后单击复制(按钮2),它将文件夹复制到另一个位置。 I would really appreciate your help! 我将衷心感谢您的帮助!

Okay, I found the resolution. 好的,我找到了解决方案。 It was wrong line picked from itemChecked. 这是从itemChecked中选择的错误行。 Right one is: 正确的是:

string P = itemChecked.FullName.ToString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM