Option Explicit On 
Option Strict On
Imports System.IO
Friend Class CopyFiles
    Friend Event Successful()
    Friend Event Failed(ByVal Reason As String)
    Private mstrSource As String
    Private mstrDestination As String
    Friend Sub StartCopying()
        Try
            Call CopyDirectory(mstrSource, mstrDestination)
            RaiseEvent Successful()
        Catch ex As Exception
            RaiseEvent Failed(ex.Message)
        End Try
    End Sub
    Private Function CopyDirectory(ByVal Src As String, ByVal Dest As String) As Boolean
        'add Directory Seperator Character (\) for the string concatenation shown later
        If Dest.Substring(Dest.Length - 1, 1) <> Path.DirectorySeparatorChar Then Dest += Path.DirectorySeparatorChar
        'If Directory.Exists(Dest) = False Then Directory.CreateDirectory(Dest)
        Dim Files() As String = Directory.GetFileSystemEntries(Src)
        For Each element As String In Files
            If Directory.Exists(element) = True Then
                'if the current FileSystemEntry is a directory,
                'call this function recursively
                Directory.CreateDirectory(Dest & Path.GetFileName(element))
                CopyDirectory(element, Dest & Path.GetFileName(element))
            Else
                'the current FileSystemEntry is a file so just copy it
                File.Copy(element, Dest & Path.GetFileName(element), True)
            End If
        Next element
    End Function
    Friend Property Source() As String
        Get
            Return mstrSource
        End Get
        Set(ByVal Value As String)
            mstrSource = Value
        End Set
    End Property
    Friend Property Destination() As String
        Get
            Return mstrDestination
        End Get
        Set(ByVal Value As String)
            mstrDestination = Value
        End Set
    End Property
End Class