|
|
|
This Code will copy all files and subfolders of specified source directory to target location |
Click here to copy the following block | Sub CopyDirectory(ByVal SourcePath As String, ByVal DestPath As String, Optional ByVal Overwrite As Boolean = False) Dim SourceDir As DirectoryInfo = New DirectoryInfo(SourcePath) Dim DestDir As DirectoryInfo = New DirectoryInfo(DestPath)
If SourceDir.Exists Then If Not DestDir.Parent.Exists Then Throw New DirectoryNotFoundException _ ("Destination directory does not exist: " + DestDir.Parent.FullName) End If
If Not DestDir.Exists Then DestDir.Create() End If
Dim ChildFile As FileInfo For Each ChildFile In SourceDir.GetFiles() If Overwrite Then ChildFile.CopyTo(Path.Combine(DestDir.FullName, ChildFile.Name), True) Else If Not File.Exists(Path.Combine(DestDir.FullName, ChildFile.Name)) Then ChildFile.CopyTo(Path.Combine(DestDir.FullName, ChildFile.Name), False) End If End If Next
Dim SubDir As DirectoryInfo For Each SubDir In SourceDir.GetDirectories() CopyDirectory(SubDir.FullName, Path.Combine(DestDir.FullName, _ SubDir.Name), Overwrite) Next Else Throw New DirectoryNotFoundException("Source directory does not exist: " + SourceDir.FullName) End If End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|