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?
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.
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).
xcopy cannot be configured to SKIP existing files, so you should copy using "robocopy".
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.
The solution is the /Y
switch:
xcopy "C:\Users\ADMIN\Desktop\*.*" "D:\Backup\" /K /D /H /Y
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With