Solved

xcopy Command

Posted on 2008-10-09
3
993 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

12 Experts available now in Live!

Get 1:1 Help Now