Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB5,VB6,VBS
Expertise: beginner
Aug 23, 2001

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:\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
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.
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap