Solved

xcopy Command

Posted on 2008-10-09
3
1,015 Views
Last Modified: 2010-05-18
I have the attached command (bat file) that I use to backup the entire contents of one drive to another.  However, the way it is currently written, it makes a new copy of every file/folder every time it runs - even if nothing has changed.  That means that it takes forever to run.

What I would really like is for it to:
1) look through every file on the 'D' drive
2) For each of those files, evaluate whether that file was modified since/after the copy that is currently on the 'G' drive.  If so, then re-copy that file onto G, otherwise, do nothing.

Could somebody tell me how to re-write to do such?
echo Begin copy >copyd.txt
date /t >>copyd.txt
time /t >>copyd.txt
echo Copying d:\* to g:\Backup >>copyd.txt
xcopy d:\* g:\Backup\ /y /i /e /v /c /h /o >>copyd.txt 2>&1
echo End copy >>copyd.txt
date /t >>copyd.txt
time /t >>copyd.txt
cls

Open in new window

0
Comment
Question by:timoteoga
3 Comments
 
LVL 3

Accepted Solution

by:
Robbals earned 500 total points
ID: 22681263

xcopy /D copies only files that are newer than the existing files.....
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 22681486
Robocopy is a good tool for this as it is more reliable and has more options than xcopy.  Its default behavior is to skip identical files which already exist in the destination.
http://en.wikipedia.org/wiki/Robocopy
0
 
LVL 16

Expert Comment

by:t0t0
ID: 22723969
Yes... You are almost there....

Just add a /M switch to your XCOPY command. This will reset the file's archive attribute.

The next time you run your batch file, all your files on D: will have their archive attributes turned off but they will still be copied to G:

From then on, every time you run your batch file only those files with their archive attributes set will be copied to G:

So, if any files change on D: for any reason, the system automatically sets the file's archive attribute back on again so that when you run your batch file at a later date, only those files that have actually changed will be copied to G:

Neat eh?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

792 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