XCOPY Switches

Posted on 2005-04-14
Last Modified: 2008-01-09
I am confused with regard to the switches in xcopy.

I want to copy files from a server to another location.

/s/e[creates subdirectorys and empty subdirectories]
/d [copies files only if the source files are newer than the destination files.

what does /m and /k do?  

I am running the xcopy command as follows and it appears to be copying modified files at the source based on the /d switch.  I want to make sure that I am doing this correctly.  Could I get an explanation on what reseting the archive bit does with /m and /k? Is it resetting a date stamp based on the source file pertaining to when it was last copied or backed up?  Am I way off base?
Question by:jmorin1
    LVL 37

    Expert Comment

    by:Harisha M G
    Hi jmorin1,
    Copies files and directory trees.

    XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                               [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
                               [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]

      source       Specifies the file(s) to copy.
      destination  Specifies the location and/or name of new files.
      /A           Copies only files with the archive attribute set,
                   doesn't change the attribute.
      /M           Copies only files with the archive attribute set,
                   turns off the archive attribute.
      /D:m-d-y     Copies files changed on or after the specified date.
                   If no date is given, copies only those files whose
                   source time is newer than the destination time.
                   Specifies a list of files containing strings.  Each string
                   should be in a separate line in the files.  When any of the
                   strings match any part of the absolute path of the file to be
                   copied, that file will be excluded from being copied.  For
                   example, specifying a string like \obj\ or .obj will exclude
                   all files underneath the directory obj or all files with the
                   .obj extension respectively.
      /P           Prompts you before creating each destination file.
      /S           Copies directories and subdirectories except empty ones.
      /E           Copies directories and subdirectories, including empty ones.
                   Same as /S /E. May be used to modify /T.
      /V           Verifies each new file.
      /W           Prompts you to press a key before copying.
      /C           Continues copying even if errors occur.
      /I           If destination does not exist and copying more than one file,
                   assumes that destination must be a directory.
      /Q           Does not display file names while copying.
      /F           Displays full source and destination file names while copying.
      /L           Displays files that would be copied.
      /G           Allows the copying of encrypted files to destination that does
                   not support encryption.
      /H           Copies hidden and system files also.
      /R           Overwrites read-only files.
      /T           Creates directory structure, but does not copy files. Does not
                   include empty directories or subdirectories. /T /E includes
                   empty directories and subdirectories.
      /U           Copies only files that already exist in destination.
      /K           Copies attributes. Normal Xcopy will reset read-only attributes.
      /N           Copies using the generated short names.
      /O           Copies file ownership and ACL information.
      /X           Copies file audit settings (implies /O).
      /Y           Suppresses prompting to confirm you want to overwrite an
                   existing destination file.
      /-Y          Causes prompting to confirm you want to overwrite an
                   existing destination file.
      /Z           Copies networked files in restartable mode.

    The switch /Y may be preset in the COPYCMD environment variable.
    This may be overridden with /-Y on the command line.

    LVL 37

    Expert Comment

    by:Harisha M G
        You can see whether the archieve bit is set by using
    dir /aa
    LVL 37

    Expert Comment

    by:Harisha M G
        In Windows, you can see file attributes by right clicking and going to properties :)

    Author Comment

    Let me better explain my dillema.  I have 2 remote workstations that I want to move files from.  Let's call them server1 and workstation1.   I want to copy files from the workstation to the server.  I also want to execute this routine without overwriting files that have remained unchanged and new files.  If I am doing this from a workstation unrelated to the two do I have to map a network drive to both server1 and workstation1?  

    Can I write a batch job that maps the drive i.e. [net use] and copies the files and disconnects the mapping upon completion?  

    LVL 37

    Expert Comment

    by:Harisha M G
    I don't think you require a mapping in the server.
    Just a map of server on workstation is suffecient.

    You can write batch file also for that.
    LVL 12

    Accepted Solution


    I suppose you are trying to maintain a backup copy.  The method you are using should work, but has the disadvantage that any files deleted from the source directory will not be deleted from the copy.   Also, in general, copying only the changed elements of data should not be your only backup....there is too much danger of some kind of failure of synchronization.

    The /M switch is an alternative to using the date to identify files that have to be copied.  Let me explain how you can use it to do weekly full and daily incremental backups.  To do this you would create two batch files, one run weekly and the the run daily.  
    The weekly batch file would do a complete new copy in the following steps.
     - rename the existing backup folder to backup.old
     - copy the entire source folder and reset all archive bits (XCOPY /S /E  )
     - delete the backup.old folder
    The daily batch file will copy only files with the archive bit (it gets set whenever a file is created or modified)
     - XCOPY /S /E /M

    However, if I were you I would use ROBOCOPY instead of XCOPY.  ROBOCOPY has a /MIR option to make a copy of a directory, and will automatically avoid unnecessary copying.  Also, for either XCOPY or ROBOCOPY, you can use an UNC path instead of a drive mapping (e.g. XCOPY \\WORKSTATION\SHARE\FOLDER C:\TEMP\FOLDER)


    LVL 1

    Assisted Solution

    If you are planning on running the batch script on an unrelated workstation2 to copy files from workstation1 to server1, you will need to establish drive mappings from workstation2 to workstation1 and from workstation2 to server1.

    The batch file would look something like this if you intend to execute it on workstation2:

    net use s: \\server1\share\ /u:userdomain\username
    net use w: \\workstation1\share\ /u:userdomain\username

    xcopy w:\path s:\path /s /e /m

    The archive bit is supposed to distinguish file which have been backed-up/archived (archive is clear) and files which are ready to be backed-up/archived (archive bit is set).  The archive bit is turned on if a file has been modified since the last time the bit was cleared.  The /m switch will only copy the files which haven't changed since the last time you ran the batch script.  

    Is this what you wanted to do or are you trying to make a new copy of each file without overwriting the files on server1?
    LVL 12

    Expert Comment


    Ooops!   Sorry, there is a big error in what I wrote earlier.  XCOPY does not clear the archive bit be default.  It seems that it only clears the archive bit when using the /M option, and that only copies file with the archive bit set on.   This means you *cannot* combine full and differential copies in the way I suggested.  In fact, it makes the /M and /A options pretty useless, IMHOP.

    I would go with ROBOCOPY.  I'm not sure if it's included with Win2K3 server, or if you have to install a server resource kit.
    You can download it from

    LVL 1

    Expert Comment

    I agree with Carlo-Giuliani.  ROBOCOPY would be the better solution.  I am pretty sure that you have to get it from the Resource Kit.  

    I didn't realize that you could use UNC paths with xcopy or robocopy.  Looks like I learned something too.  Thanks!
    LVL 1

    Expert Comment

    robocopy is a good choice, however it will fail to copy files that you dont have the permission.
    I always use robocopy and scopy in conjunction for all my migration projects.
    LVL 4

    Expert Comment

    by:marco_peereboom is a very good solution (for me at least).

    And in XCOPY?

    net use Y: \\Workstation1\C$
    net use Z: \\Server1\C$
    XCOPY /D /E /C /I /H /Y Y: Z:
    net use Y: /del
    net use Z: /del

    I think you can do this with UNC naming as well. But I think that would require quotes around the name.
    LVL 4

    Expert Comment


    I think if you want to 'mirror' your drives your answer is ROBOCOPY.  You can download Robocopy from the location provided by Carlo.
    Simply create 2 shares (source, destination) and a batch file. Schedule your batchfile and ensure ROBOCOPY is reachable (either in same directory or in your path directories such as C:\winnt\system32)

    The command you might want to use is:

    robocopy \\workstation\share \\server\share /E /Z /MIR /R:10 /W:90 /ETA /LOG+:AppendLog.log

    This will MIRROR your files from the Workstation to the Share.  Files deleted on the WS are also being deleted on the Server, it will copy empty and full subdirs, in restartable mode and if the connection drops it will wait 90 seconds before retry. It does that max. 10 times. ETA is the Estimated time of Arrival, can be replaces by /NP (No Progress).  /LOG+: is creating a log and appending to exsting log.  You could make it more dynamic of course by using  a log per day using a variable.

    If you do robocopy /??? you will get a very detailed help.  You can for example set Attiributes and check for them, so rather then using mirror you will check for that. Also you can use /SEC to copy the security information (both source / dest must be NTFS).

    Let me know your results.

    LVL 37

    Expert Comment

    by:Harisha M G
    LVL 4

    Expert Comment

    split, based on best answers according to page expert?  As in my opinion posting a xcopy /? output is not very helpful if the person asks for clarification.
    LVL 4

    Expert Comment

    BTW. The newest version of robocopy is found in the Windows 2003 RK-Tools Kit.
    It's available on:

    This version is (for as far as I've tested) running under Windows 2000, but has some new options which might be useful.

    One thing: I could't extract the rktools pack completely under W2K, so I used a WXP machine for that. After that, no problem on using the Tools.
    LVL 4

    Expert Comment

    OOPS...location already posted...SMART.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
    Windows 10 is here and for most admins this means frustration and challenges getting that first working Windows 10 image. As in my previous sysprep articles, I've put together a simple help guide to get you through this process. The aim is to achiev…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    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…

    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