Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to say no to all "do you want to overwrite" prompts in a batch file copy?

By default, copying from the command prompt will prompt you to overwrite files that already exist in the target location.

You can add "/Y" to say "Yes to all" replacements.

But how can you say "No to all" ?

In other words, I want to copy everything from one directory that does not already exist in the target.

The closest thing I see is the XCOPY argument to only copy things after a specific mod-datetime.

like image 284
JosephStyons Avatar asked Oct 10 '08 13:10

JosephStyons


People also ask

Does batch copy overwrite?

If the copy command is run from within a batch job you do not need to use the /Y switch: it will overwrite existing files.

How do I use xcopy without prompt?

Press D if you want the file or files to be copied to a directory. You can suppress this message by using the /i command-line option, which causes xcopy to assume that the destination is a directory if the source is more than one file or a directory.

Does xcopy Skip existing files?

xcopy cannot be configured to SKIP existing files, so you should copy using "robocopy".


3 Answers

Unless there's a scenario where you'd not want to copy existing files in the source that have changed since the last copy, why not use XCOPY with /D without specifying a date?

like image 178
Kev Avatar answered Sep 20 '22 14:09

Kev


echo "No" | copy/-Y c:\source c:\Dest\ 
like image 33
krishnan Avatar answered Sep 16 '22 14:09

krishnan


You can make a text file with a single long line of "n" then run your command and put < nc.txt after it. I did this to copy over 145,000 instances where "No overwrite" was what I wanted and it worked fine this way.

Or you can just hold the n key down with something, but that takes longer than using the < to pipe it in.

like image 31
Chris Avatar answered Sep 16 '22 14:09

Chris