Xcopy syntax for multiple source directories


  1. Posts : 481
    Windows 10 pro 1903 1862.145
       #1

    Xcopy syntax for multiple source directories


    can someone show me a sample xcopy command to copy C:\Directory1 and C:\Directory2 to a destination directory H:\DestinationDirectory?
      My Computer


  2. Posts : 151
    Windows 10
       #2

    try the loop,

    Code:
    for %%a in (
     "C:\Directory1"
     "C:\Directory2"
      ) do (
    xcopy /s /d "%%~a" "H:\DestinationDirectory"
      )
      My Computer


  3. Posts : 481
    Windows 10 pro 1903 1862.145
    Thread Starter
       #3

    Very good, I will use it.

    In cmd, xcopy help states "source Specifies the file(s) to copy." but does not detail how to list them.

    is the squiggle in %%~a intentional or a typo?
      My Computer


  4. Posts : 151
    Windows 10
       #4

    the above syntax is to be used in a batch file.

    here's a single liner for cmd:

    Code:
    for %a in ("C:\Directory1" "C:\Directory2") do (xcopy /s /d "%~a" "H:\DestinationDirectory")

    yes, the squiggle is intentional, it's for a short and long pathnames element.
      My Computer


  5. Posts : 481
    Windows 10 pro 1903 1862.145
    Thread Starter
       #5

    Ah, so. Odd, the d/ switch is not listed in cmd help. I changed s/ to e/ because, as a backup, I want a complete image, including empty directories.
      My Computer


  6. Posts : 481
    Windows 10 pro 1903 1862.145
    Thread Starter
       #6

    Tried and failed. My bad, probably. I cannot find how to include the actual code as you did, and copying directly to this editor removes line feeds.
      My Computer


  7. Posts : 151
    Windows 10
       #7

    tcebob said:
    Ah, so. Odd, the d/ switch is not listed in cmd help. I changed s/ to e/ because, as a backup, I want a complete image, including empty directories.
    the /d switch is for date. if not specify, only the newer files will be copied.

    tcebob said:
    Tried and failed. My bad, probably. I cannot find how to include the actual code as you did, and copying directly to this editor removes line feeds.
    You can try the single line syntax above, just double the percent sign (%a to %%a) if you wish to create a batch file.
      My Computer


  8. Posts : 481
    Windows 10 pro 1903 1862.145
    Thread Starter
       #8

    Thanks for your patient help.
    I will mark this as solved

    This is a test of the Code tags:

    Code:
    Explorer /root, \\server\share, select, Program.exe
    Aha! it worked.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 05:51.
Find Us




Windows 10 Forums