xcopy command line parameters

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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

peter_fleurOperational Director Commented:
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.

rambleAuthor Commented:

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
peter_fleurOperational Director Commented:
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 /?

Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

bbaoIT ConsultantCommented:
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)?
rambleAuthor Commented:

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.  

rambleAuthor Commented:

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?

peter_fleurOperational Director Commented:
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.

bbaoIT ConsultantCommented:
scopy is retired, replaced by new version of xcopy of windows 2000.
bbaoIT ConsultantCommented:
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.
bbaoIT ConsultantCommented:
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,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

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

bbaoIT ConsultantCommented:
yes, it does!
rambleAuthor Commented:

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?
bbaoIT ConsultantCommented:
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 ;-)
rambleAuthor Commented:

Thanks All!
rambleAuthor Commented:

Just Ignore the last comment
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.