Creating a VB routine that copies a whole directory tree can be a time-consuming job, but fortunately you don't have to do it. In fact, you can quickly create an entire folder, including all its subfolders
, using the CopyFolder method of the FileSystemObject object, that is exposed by the Microsoft Scripting Runtime type library.
If you pass False to the 3rd argument (or omit it), the CopyFolder method doesn't copy files that already exist in the destination folder.
' copy the entire contents of the C:\DOCS directory into the
' C:\BACKUP\DOCS directory, overriding existing files.
' This code assumes that you added a reference to the
' Microsoft Scripting Runtime type library
Dim fso As New Scripting.FileSystemObject
fso.CopyFolder "c:\docs", "c:\backup\docs", True