Replicate files and folders to external drive with copy command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
falcios
Posts: 43
Joined: 02 Mar 2017 05:38

Replicate files and folders to external drive with copy command

#1 Post by falcios » 03 Mar 2017 08:43

I have a batch file that copies any new, updated files to an external drive.

In one source folder, I moved quite a few files around. These files will copy but then there will be a copy in the original destination location.

Is there a way that DOS when copying to the destination folder, delete files it did not find in the source?

Thanks in advance.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Replicate files and folders to external drive with copy command

#2 Post by Squashman » 03 Mar 2017 10:00

Would be really helpful if you showed us the code you are using. I am going to assume you are not using ROBOCOPY because I believe it has the functionality you are looking for.

falcios
Posts: 43
Joined: 02 Mar 2017 05:38

Re: Replicate files and folders to external drive with copy command

#3 Post by falcios » 03 Mar 2017 10:34

Example of my current batch file

xcopy "c:\users\test\test" "e:\test" /s /e /d /y /v

Is there a switch or another DOS command, so that the files that are new, modified gets copied. File not on source but in the destination folder gets deleted from the destination folder?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Replicate files and folders to external drive with copy command

#4 Post by Squashman » 03 Mar 2017 11:05

falcios wrote:Is there a switch or another DOS command, so that the files that are new, modified gets copied. File not on source but in the destination folder gets deleted from the destination folder?

Squashman wrote:I am going to assume you are not using ROBOCOPY because I believe it has the functionality you are looking for.


Robocopy Help

Code: Select all

/MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).
/E :: copy subdirectories, including Empty ones.
/PURGE :: delete dest files/dirs that no longer exist in source.

falcios
Posts: 43
Joined: 02 Mar 2017 05:38

Re: Replicate files and folders to external drive with copy command

#5 Post by falcios » 03 Mar 2017 11:19

Thanks so much. It is exactly what I am looking for and it works great.

Post Reply