[英]How to copy directory listed in checkedListBox to another directory?
我正在嘗試制作應用程序,它將在重新安裝系統之前備份文件夾。
我現在得到的,你可以在上面看到。 點擊Button2后,我找到了“無法找到目錄”C:\\ Projects \\ WindowsFormsApplication2 \\ WindowsFormsApplication2 \\ bin \\ Debug.Desktop'。“
看來我無法正確獲取目錄的完整路徑。
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:\");
}
}
我希望用戶可以從列表中選中復選框,然后單擊復制(按鈕2),它將文件夾復制到另一個位置。 我將衷心感謝您的幫助!
好的,我找到了解決方案。 這是從itemChecked中選擇的錯誤行。 正確的是:
string P = itemChecked.FullName.ToString();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.