Copying a Folder in to a specified place

Posted on 2012-09-18
Last Modified: 2012-09-19
i am using robocopy to copy directories from one mapped drive to another with...

Shell("C:\Windows\SysWow64\Robocopy.exe C:\upsdnc\11111 C:\ups\11111_dnc /E /Z /dcopy:T /fft /R:10 /ETA /log:C:\copy.log /tee")

now i need to create variables to plug in based on a selected path in a dialog.

so for instance...

Source: J:\mill\33000s\33200s\33283

Destination: I:\ups\jobs\33000s\33200s\33283_CompanyName\dnc

See, we have numerous job #s each which a corresponding folder on the other drive. i need to find a way for the destination path to be found based on the given source path. problem is the customer name throws a kink in things. the end of the source path (job#) will always match the job # on the destination path after the 5th "\" and up to the "_" so i suppose thats a start
Question by:knutter539
    LVL 83

    Assisted Solution

    Something like below (untested)

    Dim dest As String = "I:\ups\jobs\33000s\33200s\"
    Dim src As String = "J:\mill\33000s\33200s\33283"
    Dim srcFolder As String = src.substring(src.LastIndexOf("\") + 1)

    dest &= srcFolder

    Then loop through all the companies and keep adding to dest

    Dim destFolder As String
    foreach company as string in companies
        destFolder = dest & "_" & company & "\dnc"

    Author Comment

    well the company name is irrelevant to me in this situation. the "ups" drive is where our CAD models are stored and we include the company name. once its done and ready to go to the shop, it goes to "mill". we need to now send everything in the "mill" directory to be inside of "ups" before i send it all packaged to the archive drive.

    so inside of "11111" on ups needs to be the corresponding mill folder with a _dnc added

    start: "J:\mill\11000s\11100s\11111"

    move to: "I:\ups\jobs\11000s\11100s\11111_Company\11111_dnc"

    the code i can't work through is how the program knows to pass all that company crap and know based on the job# where to stick the mill directory.

    i apologize if this system is confusing as hell

    Author Comment

    So i have 2 browse dialogs and the first is to point to src and second is pointing to where its going.

        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            Dim srcFold As String = TextBox1.Text
            Dim destFold As String = TextBox2.Text

            Shell("C:\Windows\SysWow64\Robocopy.exe" & srcFold & destFold & "/E /Z /dcopy:T /fft /R:10 /ETA /log:C:\copy.log /tee")

    says File Not Found though
    LVL 83

    Accepted Solution

    That's probably because you do not have a space after Robocopy.exe so it becomes


    Similarly at the end of destfold

    Shell("C:\Windows\SysWow64\Robocopy.exe " & srcFold & destFold & " /E /Z /dcopy:T /fft /R:10 /ETA /log:C:\copy.log /tee")

    Author Comment

    NOW im getting somewhere thank you! now it runs through but it only copies the files in mill to be inside of ups, it doesnt bring the folder itself inside of ups

        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            Dim srcFold As String = TextBox1.Text
            Dim destFold As String = TextBox2.Text

            Shell("C:\Windows\SysWow64\Robocopy.exe" & " " & srcFold & " " & destFold & " " & "/E /Z /dcopy:T /fft /R:10 /ETA /log:C:\copy.log /tee")

    ^^^ Works for the files inside of the folder
    LVL 83

    Expert Comment

    That's a robocopy issue then. I have not used it so don't know about different switches.

    Author Comment

    Ok so i have it working now to where it copies everything over except the parent directory. im accepting a solution to my original question though as it has been answered (thank you).

    All i need to figure out now is why when i select the "1111" entire job over to the archive drive, it doesnt take the parent folder.

    So with 11111_dnc in the "ups" drive the top folder is "11111_customer" which is step 1 done. i copy it to archive and it moves everything but doesnt bring "11111_customer" folder with it. possibly a setting in robocopy to take parent folder?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    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.…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 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