Question Copy an entire directory with sub directories and files to another location?

techwiz24

Well-known member
Joined
Jun 2, 2010
Messages
51
Programming Experience
Beginner
Hello. I am trying to copy a directory with sub directories and files to another location on my computer. Whenever I try, I get the following error, through my "console":

VB.NET:
$>Error: System.IO.IOException: The directory is not empty.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive)
   at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive)
   at System.IO.Directory.Delete(String path)
   at presets.mod_con.con_switch_1() in C:\Users\Administrator\Documents\Visual Studio 2010\Projects\presets\presets\mod_con.vb:line 6

The code that I am currently trying to execute is:
VB.NET:
Sub con_switch_1()
        Try
            Directory.Delete(vars.installDIR + "\Settings")
            Directory.Move(Application.StartupPath + "\Preset1\Settings", vars.installDIR + "\Settings")
            Form1.RichTextBox2.Text = Form1.RichTextBox2.Text + Environment.NewLine + "$>Controls successfully changed to Preset 1"
        Catch ex As Exception
            Form1.RichTextBox2.Text = Form1.RichTextBox2.Text + Environment.NewLine + "$>Error: " + ex.ToString
        End Try
    End Sub

Any suggestions as to what I could do with "moving" the source directory? I just want to copy it...
 
Resolved

I figured it out..it wasn't the copy that was giving me the errors. It was the delete line.

When I got rid of this:
VB.NET:
Directory.Delete(vars.installDIR + "\Settings")

And changed
VB.NET:
System.IO.Directory.Copy(Source, Destination)
to
VB.NET:
My.Computer.FileSystem.CopyDirectory(source, destination, true)

It worked great. Thank You!
 
Back
Top