Copying Folders With All Contents

Submitted by:Jhon Brain

Date added:17 October, 2011


Copying Folders With All Contents Including Other Folders. 2010 does not have a built in code to copy full folders with their contents but only files(one by one)!!!

But you can do it by this code

Tags: copying folders

Code Snippet:

Module Logic
Public Function CopyDirectory(ByVal Src As String, ByVal
Dest As String)
CopyDirectory = False
If Not Directory.Exists(Src) Then
CopyDirectory = "%%SRCNOTEXITS%%"
Exit Function
End If
If Dest.Substring(Dest.Length - 1, 1) <>
Path.DirectorySeparatorChar Then
Dest += Path.DirectorySeparatorChar
End If
If Not Directory.Exists(Dest) Then
Dim Files As String()
Files = Directory.GetFileSystemEntries(Src)
Dim element As String
For Each element In Files
If Directory.Exists(element) Then
CopyDirectory(element, Dest &
File.Copy(element, Dest &
Path.GetFileName(element), True)
End If
Return True
End Function
End Module