Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCOPY: Overwrite all without prompt in BATCH

I'm writing a batch program for copying all files newer than the destination from "C:\Users\ADMIN\Desktop" to "D:\Backup".

This code is works:

xcopy "C:\Users\ADMIN\Desktop\*.*" "D:\Backup\" /K /D /H 

However, it asks for each existing destination file: Overwrite file [Yes / No / All]?

I want to overwrite all existing destination files without user intervention.

How can I solve this?

like image 489
FZs Avatar asked Oct 31 '17 09:10

FZs


People also ask

How do I overwrite xcopy?

If I want to overwrite the entire contents of the folder, what should I add to my code? As noted in this SS64 page on XCOPY , the /Y option suppresses the prompt to confirm overwriting a file.

How do I overwrite a batch file?

This setting may be overridden with /-Y on the command line. The default is to prompt on overwrites unless COPY command is being executed from within a batch script. To append files, specify a single file for destination, but multiple files for source (using wildcards or file1+file2+file3 format).

Does xcopy Skip existing files?

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

Does Copy command overwrite?

Usually, when you run a cp command, it overwrites the destination file(s) or directory as shown. To run cp in interactive mode so that it prompts you before overwriting an existing file or directory, use the -i flag as shown.


1 Answers

The solution is the /Y switch:

xcopy "C:\Users\ADMIN\Desktop\*.*" "D:\Backup\" /K /D /H /Y 
like image 153
FZs Avatar answered Oct 05 '22 07:10

FZs