File.Copy Entire Directory to another Directory

Posted on 2008-11-14
Last Modified: 2013-11-07
I want to copy an entire directory to another destination. I get


            destination = "C:\jeffrey\"

            strSourcePath = "C:\moves\"
            strDestPath = destination
            File.Copy(strSourcePath, strDestPath)

Error Message;
Could not find a part of the path 'C:\moves\'.

Question by:jseaman12
    LVL 6

    Accepted Solution

    is it vb thats used for this.. i use this in a VB application of mine
    My.Computer.FileSystem.CopyDirectory(SRCTB.Text, DSTTB2.Text)

    SRCTB.Text, DSTTB2.Text are source and destination locations fed dynamically from TEXT box
    LVL 18

    Assisted Solution

    from the code I see you are using VB.NET. IF yes, then you can use this method

    My.Computer.FileSystem.CopyDirectory(strSourcePath, destination)

    if you are using c#, then you would need to do a recursive loop trough each subdirectory and copy all files in them.
    LVL 6

    Expert Comment

    Was my idea helpful?
    LVL 6

    Expert Comment

    were you able to test my solution?

    Expert Comment

    I found this helpful.  It would be great to see how to loop through and restrict copying of specific files.  For example, if you wanted to copy all files in the directory except those that contained "secure" in the name.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now