Search code examples
visual-studioxcopy

Visual Studio 2010: CopyDirectory or xcopy to copy Whole Directory


I would like to copy whole directory to another directory. xcopy and My.Computer.FileSystem.CopyDirectory only copies the "Content" of the directory.

For example: If source: C:\Users\Myfile555\ and Destination: C:\Dest\

I would want the files to be copied to C:\Dest\Myfile555

On my Visual Studio Application, I made Source and Destination Folder button. so i could select the folder \Myfile555 as source.

and whatever I chose as destination folder(example: \Desktop), It would become \Desktop\Myfile555.

Anyone has any tips on doing so ? Any help is greatly appreciated. Thank you everyone.


Solution

  • The source codes that I've tried:

    Dim sourcepath = TextBox1.Text
    Dim destpath = TextBox2.Text
    

    Btn1:

    Shell("cmd /k xcopy """ & sourcepath & """ """ & destpath & """ /D /E /C /I /R /H /K /Y")
    

    Btn2:

    My.Computer.FileSystem.CopyDirectory(sourcepath, destpath, True)
    

    Both commands only copy the CONTENTS of the folder, but I would like to copy both the CONTENTS + the ORIGINAL folder all the files were in.

    Thank you.