Having XCopy copy a file and not overwrite the previous one if it exists (without prompting)

前端 未结 7 1599
独厮守ぢ
独厮守ぢ 2021-01-01 11:50

I\'m sending a commands to a remote computer in order to have it copy a file. I want the file to be copied, but not to overwrite the previous file with the same name (if it

相关标签:
7条回答
  • 2021-01-01 12:20

    You can also use the replace command. It has two modes: to add files that don't exist there or replace files that do exist. You want the previous mode:

    replace <path1> <path2> /A
    
    0 讨论(0)
  • 2021-01-01 12:22

    Following command copy files and folder but not override file if already exist.

    xcopy "*.*" "C:\test\"  /s /y /d
    
    0 讨论(0)
  • 2021-01-01 12:26

    Well, there's a certain remedy! It has helped me with saving much of my effort and time on Win10 while writing a setup for our product demo.

    Just try to use piping:

    @ECHO N|COPY /-Y SourceFiles Destination

    As an example I used this piece of code so that I would have a clean gentle quiet and safe copy!

    @FOR /D %%F in ("FooPath") DO @(
       @ECHO N|COPY /-Y ^"%%~npdxF\*.*^" ^"GooPath^" 3>NUL 2>NUL >NUL
    )
    

    where obviously FooPath is the source and GooPath is the destination.

    Enjoy!

    (main source: https://ss64.com/nt/copy.html)

    0 讨论(0)
  • 2021-01-01 12:31

    I have good results with xcopy /d.

    It will copy NEWER files, and since we can assume that existing files have same time-stamp, you will copy only files that don't exist.

    0 讨论(0)
  • 2021-01-01 12:33

    No way to make it NOT overwrite as far as I know. but /Y will make it overwrite. and /I will get rid of the file/dict prompt. See xcopy /? for all options

    0 讨论(0)
  • 2021-01-01 12:33

    I had to copy AND rename files, so I got the prompt about creating a file or a directory.

    This is the, rather "hackish" way I did it:

    ECHO F | XCOPY /D "C:\install\dummy\dummy.pdf" "C:\Archive\fffc810e-f01a-47e8-a000-5903fc56f0ec.pdf"
    

    XCOPY will use the "F" to indicate it should create the target as a file:

    C:\install>ECHO F   | XCOPY /D "C:\install\dummy\dummy.html" "C:\Archive\aa77cd6e-1d19-4eb4-b2a8-3f8fe60daf00.html"
    Does C:\Archive\aa77cd6e-1d19-4eb4-b2a8-3f8fe60daf00.html specify a file name or directory name on the target
    (F = file, D = directory)? F
    C:\install\dummy\dummy.html
    1 File(s) copied
    

    I've also verified this command leaves existing files alone. (You should too :-)

    0 讨论(0)
提交回复
热议问题