Copy files do not overwrite existing

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zombie_funk
Posts: 2
Joined: 30 May 2009 15:41

Copy files do not overwrite existing

#1 Post by zombie_funk » 30 May 2009 15:49

Hi there,
In the spirit of DIY I would like to create a batch file to backup my music library, however I would like to it to only add new files to the backup.

something like:

Code: Select all

COPY E:\*.mp3 F:\music\

What would I need to do to make sure that it doesn't overwrite files that already exist?

Thanks

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#2 Post by RElliott63 » 30 May 2009 23:27

Use the copy /-Y option

Something like:

COPY /-Y E:\*.mp3 F:\music\

This will prompt you to overwrite or not. That way, you can copy them all, or overwrite as it's copying. But, it won't overwrite unless you tell it to.

-Rick

zombie_funk
Posts: 2
Joined: 30 May 2009 15:41

#3 Post by zombie_funk » 31 May 2009 13:04

Thanks Rick,
That worked great for initially copying my files over but when I tried my first "Backup" it prompted me to overwrite each file individually.

Code: Select all

COPY /-Y E:\*.mp3 F:\music\
E:\01 Limehouse Blues.mp3
Overwrite F:\MP3Mass\01 Limehouse Blues.mp3? (Yes/No/All):


I would like the script to only copy new files over (files that do not exist in the backup folder, to save time)

Perhaps I need to send the output to a loop that returns "no"?
Or maybe I should compare the files in the two locations first, then only copy new files over with a more elaborate script?

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#4 Post by RElliott63 » 31 May 2009 15:41

OK.. try this then:

XCopy /-U E:\*.mp3 F:\music\

The /U option will only copy files that already exist. The /-U should copy only those that do not already exist.

-Rick

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#5 Post by avery_larry » 01 Jun 2009 11:35

If you want to take the time to learn it, robocopy is an excellent tool designed just for this type of thing.

From the resource toolkit.

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: Copy files do not overwrite existing

#6 Post by ChickenSoup » 13 Dec 2010 10:38

Old topic, but I thought I would post.

pipe an 'n' to each question on the overwrite. the /-y is required in batch files or it assumes /y.

Code: Select all

echo n|copy /-y c:\source\* c:\destination\*

Post Reply