Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 14956

how to: Copy folder to Desktop

$
0
0
I'm trying to drag a folder from Explorer and put the directory in the Desktop folder. I have some code that's close. It's copying all the files "inside" the folder and putting them on the Desktop.

Any help appreciated...
Code:

    Private Sub ListView1_DragDrop(sender As Object, e As DragEventArgs) Handles ListView1.DragDrop
        Dim files() As String = CType(e.Data.GetData(DataFormats.FileDrop), String())
        For Each item In files
            If Directory.Exists(Path.Combine(CStr(item), DesktopPath & "\")) Then
                'copies all the files within directory, but not the folder itself
                My.Computer.FileSystem.CopyDirectory(CStr(item), DesktopPath)
            Else
                File.Copy(CStr(item), Path.Combine(DesktopPath, Path.GetFileName(CStr(item))))
            End If
        Next
    End Sub


Viewing all articles
Browse latest Browse all 14956

Trending Articles