Copying All Contents of One Folder into another

  • Thread starter Thread starter Jason Moss
  • Start date Start date
J

Jason Moss

How would I copy all the contents of one folder (Including all subfolders +
files) in VB.NET? Could you please provide source code or step by step
instructions (I'm only a novice)

-Jason
 
Hi Jason

See directorymove in this folder
http://msdn.microsoft.com/library/d...html/frlrfsystemiodirectoryinfoclasstopic.asp

There is not command as Xcopy in VB.net, you have to loop through all
folders and when it is moving you have to do that recursivly however that
is not really beginners stuff.

(Or try a commandline command which I really do not know if it works however
you can try it using)

\\\
Dim p As New Process
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = False
p.StartInfo.Arguments = "\?"
p.StartInfo.WorkingDirectory = "C:\mydir"
p.StartInfo.FileName = "myProg.exe"
p.Start()
///

I hope this helps,

Cor
 
How about something like this.

Public Sub CopyDirectory(ByVal strSrc As String, ByVal strDest As String)
Dim dirInfo As New System.IO.DirectoryInfo(strSrc)
Dim fsInfo As System.IO.FileSystemInfo

If Not System.IO.Directory.Exists(strDest) Then
System.IO.Directory.CreateDirectory(strDest)
End If

For Each fsInfo In dirInfo.GetFileSystemInfos
Dim strDestFileName As String = System.IO.Path.Combine(strDest,
fsInfo.Name)

If TypeOf fsInfo Is System.IO.FileInfo Then
System.IO.File.Copy(fsInfo.FullName, strDestFileName, True)
'This will overwrite files that already exist
Else
CopyDirectory(fsInfo.FullName, strDestFileName)
End If

Next

End Sub
 
Back
Top