RSS Feeds

Tuesday, October 23, 2007

Copy Files From One Directory To Another in VB.NET

This is General Function, That You can Use

using System.IO

Public Sub CopyDir(ByVal strSrc As String, ByVal strDest As String)
Dim dirInfo As New DirectoryInfo(strSrc)
Dim fsInfo As FileSystemInfo
If Not Directory.Exists(strDest) Then
Directory.CreateDirectory(strDest)
End If
For Each fsInfo In dirInfo.GetFileSystemInfos
Dim strDestFileName As String = Path.Combine(strDest, fsInfo.Name)
If TypeOf fsInfo Is FileInfo Then
File.Copy(fsInfo.FullName, strDestFileName, True)
'This will overwrite files that already exist
Else
CopyDir(fsInfo.FullName, strDestFileName)
End If
Next
End Sub

2 comments:

Anonymous said...
This comment has been removed by a blog administrator.
Abhishek Sur said...

Clear and Best...

Great to see this.

Post a Comment