Public Sub PasteFile()
For Each Me.lItem In leftListView.Items

                If lItem.Selected = True Then
                    If File.Exists(lItem.Text) Then
                        lItem.ToString()

                        fSource = leftCBselect.Text & lItem.Text
                        Me.fTarget = rightCBselect.Text & lItem.Text
                        FileCopy(fSource, Me.fTarget)
                        rightListView.Items.Add(lItem.Clone)
                        'MsgBox("You have copied " & lItem.Text & " succesfully!", MsgBoxStyle.Information, "Information")

                    ElseIf Directory.Exists(lItem.Text) Then
                        fSource = leftCBselect.Text & lItem.Text
                        Me.fTarget = rightCBselect.Text & lItem.Text
                        My.Computer.FileSystem.CopyDirectory(fSource, Me.fTarget)
                        rightListView.Items.Add(lItem.Clone)
                    End If
                End If
            Next
End Sub

hello.

i have 2 listviews in which folder and files are loaded.
i'm trying to make a function that, when "Copy" button is pressed copies files/ folders between listviews (between folders "ex: from "D:\path" to "E:\path\subpath"). the codes of file copy and folder copy both work but not if add the file.exists / folder.exists lines. if i put a msgbox instead of the filecopy/ foldercopy it displays "file exists" or "folder exist" etc. .. but if add the file copy / folder copy line doens't do nothing.

this also happend when trying to do a dragndrop

Private Sub rightListView_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles leftListView.DragDrop, rightListView.DragDrop

        Dim fSource, fTarget As String
        For Each Me.lItem In leftListView.Items
               If lItem.Selected = True Then
               fSource = leftCBselect.Text & lItem.Selected
               fTarget = rightCBselect.Text
               FileCopy(fSource, fTarget)
               rightListView.Items.Add(lItem.Clone())
            End If
        Next


    End Sub

any ideas?

Recommended Answers

All 3 Replies

i've figured out the file/folder exists problem .. kind of easy :|

Sub PasteFile()

        If leftListView.Focused = True Then

            For Each Me.lItem In leftListView.Items

                If lItem.Selected = True Then

                    lItem.ToString()

                    fSource = leftCBselect.Text & lItem.Text
                    Me.fTarget = rightCBselect.Text & lItem.Text
                    If File.Exists(fSource) = True Then
                        My.Computer.FileSystem.MoveFile(fSource, Me.fTarget)
                    ElseIf Directory.Exists(fSource) = True Then
                        My.Computer.FileSystem.MoveDirectory(fSource, Me.fTarget)
                    End If
                    rightListView.Items.Add(lItem.Clone)
                    
                    MsgBox("You have copied " & lItem.Text & " succesfully!", MsgBoxStyle.Information, "Information")


                End If
            Next
End Sub

any ideas for the drag n drop . when drag n drop is finished it should copy the selected file

at drag and drop i've just put the pasteFile() line

Private Sub rightListView_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles leftListView.DragDrop, rightListView.DragDrop
 
       pasteFile()
 
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.