Link to home
Start Free TrialLog in
Avatar of tkeeler1
tkeeler1

asked on

Copy all Files and Folders in Visual Basic

Hi,

  I'm trying to copy all files and folders in one directory to another directory.  The problem is that "CopyFolder" also copies the original directory.  I need to have all the files and folders to be copied to the root of the other directory.  For instance, I need to copy everything in C:\MyStuff to the root of E:\ (without the MyStuff folder).

  I have the following code:
            Dim MyObj 'As New FileSystemObject
            Set MyObj = CreateObject("Scripting.FileSystemObject")
           
            If MyObj.FolderExists(startpath) Then
                MyObj.CopyFolder startpath, destpath
            End If

But as I said, this method copies the "MyStuff" folder also, and not just the contents.

Any ideas?

Thank you,
TK
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

The DOS command xcopy will copy a folder and all its contents

shell("xcopy c:\1 c:\2")

Copies everything from folder 1 into folder 2.

You may need to set some command line switches to handle sertain scenarios.

Hope this helps.
-Jim
Avatar of tkeeler1
tkeeler1

ASKER

I can't use shell commands for my app.  Can you do the same thing with a FileSystemObject?

Thanks,
TK
ASKER CERTIFIED SOLUTION
Avatar of iHadi
iHadi
Flag of Syrian Arab Republic image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great!  This works.  Thanks a bunch iHadi.....

-TK
Your welcome tkeeler1