devxlogo

Copy a directory tree

Copy a directory tree

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.

' copy the entire contents of the C:DOCS directory into the' C:BACKUPDOCS directory, overriding existing files.'' This code assumes that you added a reference to the ' Microsoft Scripting Runtime type libraryDim fso As New Scripting.FileSystemObjectfso.CopyFolder "c:docs", "c:ackupdocs", True

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.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist