Question

XCOPY Switches

Asked by: jmorin1

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?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-04-14 at 11:19:54ID21389225
Tags

xcopy

,

switches

Topic

Operating Systems Miscellaneous

Participating Experts
6
Points
500
Comments
19

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. xcopy in win95
    How do I get xcopy to run from the a: drive using switches /h/r/k without booting windows?
  2. XCOPY question
    Hello, I have a PC running DOS 6.2. I would like to write a batch file that uses XCOPY to copy the files from one directory to another based on the current date and time. Since this batch file runs frequently, I only want to copy the newer files and want to avoid re-copy...
  3. W2K xcopy problem
    Hi , fellows. I work with W2K. I want to copy one file into another existing file using xcopy. xcopy /R file1 file2 And I get this: Overwrite file2 (Yes/No/All)? 1) Why does this happen ? 2)How can I avoid this question ?
  4. Xcopy
    Can Anyone tell me the old way of copying data HDD to HDD without ghost??? Xcopy command if I remember rightly
  5. XCOPY or FORFILES
    Hi there. I simply need to copy a file from a directory on one machine to a directory on another box for processing. We receive these files daily except for Saturday. There are many other files in the source directory, and I'm unsure how to specify that I get only the most...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: mgh_mgharishPosted on 2005-04-14 at 11:29:22ID: 13784469

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]
                           [/EXCLUDE:file1[+file2][+file3]...]

  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.
  /EXCLUDE:file1[+file2][+file3]...
               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.


Bye
---
Harish

 

by: mgh_mgharishPosted on 2005-04-14 at 11:30:34ID: 13784483

jmorin1,
    You can see whether the archieve bit is set by using
dir /aa

 

by: mgh_mgharishPosted on 2005-04-14 at 11:37:56ID: 13784575

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

 

by: jmorin1Posted on 2005-04-14 at 12:00:30ID: 13784774

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?  

 

by: mgh_mgharishPosted on 2005-04-14 at 12:06:06ID: 13784826

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.

 

by: Carlo-GiulianiPosted on 2005-04-14 at 12:31:52ID: 13785034

Hi,

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)

 

 

by: eml32118Posted on 2005-04-14 at 12:40:28ID: 13785106

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?

 

by: Carlo-GiulianiPosted on 2005-04-14 at 13:41:05ID: 13785715


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 http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

 

by: eml32118Posted on 2005-04-14 at 14:34:59ID: 13786271

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!

 

by: mohaiPosted on 2005-04-14 at 19:43:14ID: 13787616

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.

 

by: marco_peereboomPosted on 2005-04-19 at 02:12:35ID: 13813655

http://www.xxcopy.com/ 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.

 

by: DaGo21Posted on 2005-04-19 at 03:08:13ID: 13813899

Hi;

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.

 

by: mgh_mgharishPosted on 2005-05-25 at 00:52:36ID: 14075276

Split

 

by: DaGo21Posted on 2005-05-25 at 07:37:50ID: 14077807

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.

 

by: marco_peereboomPosted on 2005-05-25 at 08:44:58ID: 14078564

BTW. The newest version of robocopy is found in the Windows 2003 RK-Tools Kit.
It's available on: http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&DisplayLang=en

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.

 

by: marco_peereboomPosted on 2005-05-25 at 08:46:02ID: 14078577

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

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...