How to overwrite existing files in batch?

后端 未结 10 1311
猫巷女王i
猫巷女王i 2021-01-30 15:17

The following command copies and moves a file but I also need it to overwrite the file it\'s replacing.

xcopy /s c:\\mmyinbox\\test.doc C:\\myoutbox
相关标签:
10条回答
  • 2021-01-30 15:58

    Add /Y to the command line

    0 讨论(0)
  • 2021-01-30 15:59

    Here's what worked for me to copy and overwrite a file from B:\ to Z:\ drive in a batch script.

    echo F| XCOPY B:\utils\MyFile.txt Z:\Backup\CopyFile.txt /Y
    

    The "/Y" parameter at the end overwrites the destination file, if it exists.

    0 讨论(0)
  • 2021-01-30 16:00

    If destination file is read only use /y/r

    xcopy /y/r source.txt dest.txt
    
    0 讨论(0)
  • 2021-01-30 16:01

    A command that would copy in any case

    xcopy "path\source" "path\destination" /s/h/e/k/f/c/y
    
    0 讨论(0)
  • 2021-01-30 16:07

    you need to simply add /Y

    xcopy /s c:\mmyinbox\test.doc C:\myoutbox /Y
    

    and if you're using path with spaces, try this

    xcopy /s "c:\mmyinbox\test.doc" "C:\myoutbox" /Y
    
    0 讨论(0)
  • 2021-01-30 16:09

    Add /y to the command line of xcopy:

    Example:

    xcopy /y c:\mmyinbox\test.doc C:\myoutbox
    
    0 讨论(0)
提交回复
热议问题