使用vb.net将文件夹从复选框1移动到2

本文关键字:移动 复选框 vb net 文件夹 使用 | 更新日期: 2023-09-27 18:14:21

我有两个复选框。一个是我要复制的文件夹列表。第二个是我要复制文件夹到的位置列表

事情是我不知道如何单击复选框并移动到该位置。我所做的就是设置一个固定位置,我可以从文件夹test复制到文件夹test。但我想选择清单中的勾号,从框1移动到框2,而不是固定的位置和文件夹。

Private Sub moveContainerToLocation_Click(sender As System.Object, e As System.EventArgs) Handles moveContainerToLocation.Click
    'To do
    Try
        Dim fileToCopy As String
        Dim NewCopy As String
        Dim fileSize As Long

        ' fileToCopy is folder i want to move 
        ' NewCopy  is the location what we choose to move the folder to

        fileToCopy = "C:'folder test"
        NewCopy = "C:'folder"
        fileSize = GetFolderSize(fileToCopy)
        ' allow to overwrite
        My.Computer.FileSystem.CopyDirectory(fileToCopy, NewCopy, True)
        Timer1.Start()
        moveContainerToLocation.Enabled = False

        ' the percentage of files transferred and use it into the progressbar
        Dim counter =Directory.GetFiles(fileToCopy,"*",SearchOption.AllDirectories).Length
        'Next
    Catch ex As Exception
       MessageBox.Show("ERROR")
    End Try
End Sub

"这是我的文件夹在我的checklistbox1

Private Sub GetfolderButton_Click(sender As System.Object, e As System.EventArgs) Handles GetContainerButton.Click
    For Each dra As String In Directory.GetDirectories("C:'folder test")
        Container.Items.Add(dra)
    Next
End Sub

"这是获取我的位置在我的checklistbox1

Private Sub getLocationButton_Click(sender As System.Object, e As System.EventArgs) Handles getLocationButton.Click
    For Each dr As String In Directory.GetDirectories("C:'folder")
        Location.Items.Add(dr)
    Next

End Sub

使用vb.net将文件夹从复选框1移动到2

如果我正确理解你的问题,你是在问如何在CheckedListBox中获得选中的项目,对吗?第一件事是,在一个CheckedListBox '中可能有多个选中的项目。所以你不会得到一个答案。

If CheckedListBox1.CheckedItems.Count = 0 Then
    MsgBox("Please select something")
    Return
ElseIf CheckedListBox1.CheckedItems.Count > 1 Then
    MsgBox("Please select only one item")
    Return
End If
NewCopy = CheckedListBox1.CheckedItems(0)