0

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.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
FerX32
  • 1,407
  • 3
  • 18
  • 28

2 Answers2

0
        string[] returnR = null;
        returnR = Directory.GetFiles(textBox3.Text + @"\", "*.xls"); ///get all excel files

then, you just have to do the foreach loop to copy one file from returnR array to your folder

Andrew
  • 7,619
  • 13
  • 63
  • 117
  • Thank you for the help but I don't think you understood the question correctly. Basically, I would like to copy the "whole" folder, including the folder it self. so if I want to copy C:\"FolderEx1" to C:\Desktop\, then it would become C:\Desktop\"FolderEx1". I am not really trying to copy only the contents inside the folder but the contents AND the ORIGINAL folder it self. – FerX32 Apr 06 '12 at 00:50
0

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.

Code Maverick
  • 20,171
  • 12
  • 62
  • 114
FerX32
  • 1,407
  • 3
  • 18
  • 28