This might help you.
Its part of a recursive file copy routine from one of my apps but it should give you ideas so you can modify to suit.
You'll see that there is a switch 'fRecursive' which enables or disables the recursive ability. If enabled, it re-enters at the line -
If Not RecursiveDirectoryCopy(sDirInfo.FullName, dDirInfo.FullName, fRecursive, overWrite) Then
I've trimmed out a fair bit of code thats irrelevant to you but I think this should still function ok.
Public Function RecursiveDirectoryCopy(ByVal sourceDir As String, ByVal destDir As String, ByVal fRecursive As Boolean, ByVal overWrite As Boolean) As Boolean
Dim str As String
Dim sDir As String
Dim sDirInfo As IO.DirectoryInfo
Dim dDirInfo As IO.DirectoryInfo
Dim sFile As String
Dim sFileInfo As IO.FileInfo
Dim dFileInfo As IO.FileInfo
' Add trailing separators to the supplied paths if they don't exist.
If Not sourceDir.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()) Then
sourceDir &= System.IO.Path.DirectorySeparatorChar
End If
If Not destDir.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()) Then
destDir &= System.IO.Path.DirectorySeparatorChar
End If
'If destination directory does not exist, create it.
dDirInfo = New System.IO.DirectoryInfo(destDir)
If dDirInfo.Exists = False Then dDirInfo.Create()
dDirInfo = Nothing
' Recursive switch to enable drilling down into directory structure.
If fRecursive Then
' Get a list of directories from the current parent.
For Each sDir In System.IO.Directory.GetDirectories(sourceDir)
sDirInfo = New System.IO.DirectoryInfo(sDir)
dDirInfo = New System.IO.DirectoryInfo(destDir & sDirInfo.Name)
' Create the directory if it does not exist.
If dDirInfo.Exists = False Then dDirInfo.Create()
' Since we are in recursive mode, copy the children also
If Not RecursiveDirectoryCopy(sDirInfo.FullName, dDirInfo.FullName, fRecursive, overWrite) Then
Return False
End If
sDirInfo = Nothing
dDirInfo = Nothing
Next
End If
' Get the files from the current parent.
Try
For Each sFile In System.IO.Directory.GetFiles(sourceDir)
If Not bHalted Then 'user cancelled?
sFileInfo = New System.IO.FileInfo(sFile)
dFileInfo = New System.IO.FileInfo(Replace(sFile, sourceDir, destDir))
progbar_2.Value = CInt(IIf((iFiles >= Me.progbar_2.Maximum), Me.progbar_2.Maximum, iFiles))
iFiles += 1
str = "Copying " & sFileInfo.Name & " to " & dFileInfo.FullName
AddToRtfLog(str & " - " & iFiles & " of " & iFileCount, Color.Black)
AddTolblStatus("Copying files to the local buffer..." & vbNewLine & " " & iFiles & " of " & iFileCount, Color.Aqua)
Me.Refresh()
'If File does not exist. Copy it to buffer.
Dim iAttempts As Integer = 0
If dFileInfo.Exists = False Then
Try
If CopyProgress(sFileInfo.FullName, dFileInfo.FullName) Then
'increment 'copied' counter as real filecount flag - no copies= no zip
iCopyCount += 1
str = "Copied " & sFileInfo.Name & " to " & dFileInfo.FullName
AddToRtfLog(str, Color.Green)
Else
GoTo cleanup
End If
Catch ex As Exception
AddToRtfLog("RecursiveDirectoryCopy - CopyProgress error" & vbNewLine & _
" Error is - " & ex.Message.ToString, Color.Red)
End Try
End If
sFileInfo = Nothing
dFileInfo = Nothing
Else
GoTo cleanup
End If
Next
Catch ex As Exception
rejectRootFolder = sourceFileFolder
AddToRtfLog("Error in drop folder " & sourceDir & vbNewLine & _
"This folder will be deleted. Error is - " & ex.Message.ToString, Color.Red)
Return False
End Try
Return True
cleanup:
str = "Halting cloning process..."
AddToRtfLog(str, Color.Black)
Try
sFileInfo = Nothing
dFileInfo = Nothing
Catch ex As Exception
'
End Try
Return False
End Function 'RecursiveDirectoryCopy