Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


xcopy command line parameters

Posted on 2003-12-10
Medium Priority
Last Modified: 2012-05-04
Below are the xcopy command-line parameters:


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.


Lets say that I backup

c:\dir1   to   d:\backup\dir1

I use, practically all of the command-line args...so I do a recursive, all sub directories...etc.


Now, lets say that I DELETE c:\dir1\myfiles\documents\not_important.doc

When the xcopy runs, I want the destination (d:\backup\dir1\myfiles\documents\not_important.doc) to be removed...since it no longer exists in the source.

Do I need to write another program (or find another program) to do this?  What do ya'll suggest?

If there is a free program out there that does this, it needs to also copy over the permissions (ACLs etc.).  But I haven't found one.

Thanks IA for any info.

Question by:ramble
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 3
  • +1

Assisted Solution

peter_fleur earned 1000 total points
ID: 9916883
We use robocopy for these kind of processes. It copies permissions and it can make mirrors of complete directory structures.
You can find robocopy on the resource kits of microsoft:


Hope this will answer your question.


Author Comment

ID: 9920348

This looks like it will work.  I'll work on it today.  robocopy has a command line parameter:
            /PURGE : delete dest files/folders that no longer exist in source.
That appears to be what I'm looking for.

Although it's labeled for 2003 Server, I'm guessing that it will work on 2000

Expert Comment

ID: 9920479
It will work on a Windows 2000 machine. They upgraded the resource kits but the tools are all the same except for some new extra 2003 files. You can also use the /mirror line parameter. I don't really know the difference now but it's described in the /?

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

LVL 37

Expert Comment

ID: 9921223
quoted from RK's documenation: RoboCopy is a 32-bit Windows command-line application that simplifies the task of maintaining an identical copy of a folder TREE in multiple locations, either on the same computer or in separate network locations. RoboCopy can provide time-efficient maintenance of mirror images of large folder trees on network servers separated by slow or unreliable wide area networks (WANs) links.

RoboCopy can maintain directory TREE, not their content, so i dont think it is what ramble needs.

ramble, it sounds that you need a full content synchronization of folder(s)?

Author Comment

ID: 9921299

Well, I'm going to experiment with it a little.  Initially, it sure looks to me that it does everything xcopy does...but more.  bbao: what makes you think it doesn't maintain their content as well?


bbao: you are correct, I'm wanting full content synchronziation as well.  


Author Comment

ID: 9921340

Hey...on that link I posted above...down below called "related links", it looks like scopy might be good.  Sure seems simple to use.  Do you guys have any experience with scopy?


Expert Comment

ID: 9921387
In my experience robocopy does copy content too. It keep the NTFS security too so not only the tree but also the files in it. And you can make a mirror with the /MIR command line function.

LVL 37

Expert Comment

ID: 9921782
scopy is retired, replaced by new version of xcopy of windows 2000.
LVL 37

Expert Comment

ID: 9921812
peter_fleur, yes, robocopy does copy content too, as well as other *copy utilities do. but what ramble needs is  "full content synchronization of folder(s)", please read above posts.
LVL 37

Accepted Solution

bbao earned 200 total points
ID: 9921973
hi folks, i got idea!

try the following commands:

attrib d:\backup\dir1 -a /s
xcopy c:\dir1 d:\backup\dir1 /s /v /e /z
del d:\backup\dir1 /a-a /f /s /q

it does exactly what you want: copy all the source dir and its content to the backup folder, then delete all the files that do not exist at source locations.

btw, i would suggest you use replace.exe to replace xcopy.exe, to prevent copy duplicate files, but be sure you should have right archive attribute set for all files.

hope it helps,

Expert Comment

ID: 9927685

then what is the need for the backup if it also deletes the file when it is deleted from the source??

LVL 37

Expert Comment

ID: 9927703
yes, it does!

Author Comment

ID: 9928187

notch_ur_head: That's actually what I'm looking for.  Without it, then the the files in the backup (or the overall backup set) would become bloated with time...full of old temporary files that nobody wants anymore.

I have 20 120GB harddrive (firewire & USB 2.0)...so I propagate the backups down the line...eg. D=>E, E=>F,F=G... Then I run a weekly tape backup for archival purposes.

But, thanks to all,  I have plenty of backup info.  I'll probably use robocopy or xxcopy:

robocopy and xxcopy comparison: http://www.xxcopy.com/xxcopy30.htm

bbao: I'm still not sure, maybe I'm being dense, why you don't think robocopy (or xxcopy for that matter) wouldn't work???  It seems to be relatively robust, and the /PURGE or /MIR option appears to do exactly what your script is doing.

Do you mind expanding on that?
LVL 37

Expert Comment

ID: 9928424
ramble, just had a try robocopy 1.96 on my machine, yes! it does what my batch does and even better and more. i am wondering why my robocopy /? only shows /mir option, so i did think robocopy does not support those options. in fact, i did not know robocopy before, and nice to learn about such a power tool. anyway, my batch is not bad too, especially when you work on old systems or those without RK installed, hehe ;-)

Author Comment

ID: 9928601

Thanks All!

Author Comment

ID: 10893570

Just Ignore the last comment

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
What monsters are hiding in your child's room? In this article I will share with you a tech horror story that could happen to anyone, along with some tips on how you can prevent it from happening to you.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

597 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