Copying a folder and it's contents in vb.net

vb.net

Solution

You can't just copy a directory and all of it's contents with one line of code. You can however "cut and paste" a directory with:

Directory.Move("C:\Users\Max\Desktop\test\" & sender.name, "C:\Users\Max\Desktop\test2\" & sender.name)

To copy you'll need to create a new folder of the same name in the destination directory then copy the contents into it:

Dim SourcePath As String = "C:\Users\Max\Desktop\test\" & sender.name
Dim DestinationPath As String = "C:\Users\Max\Desktop\test2"
Dim newDirectory As String = System.IO.Path.Combine(DestinationPath, Path.GetFileName(Path.GetDirectoryName(SourcePath)))
If Not (Directory.Exists(newDirectory)) Then
     Directory.CreateDirectory(newDirectory)
End If
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(SourcePath, newDirectory)

Problem

I want to copy a specific folder and it's contents using vb.net, the methods I found all just copy the contents of the specified folder but not the folder as a whole. I want the folder that the path leads to to be copied fully and not only the contents.I have this code at the moment: ``` Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory("C:\Users\Max\Desktop\test\" & sender.name, "C:\Users\Max\Desktop\test2") ```

Original source