Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy Only Missing Files

Tags:

batch-file

Let me preface this question by saying that I am relatively new to writing batch files, so I apologize if my question seems remedial.

I'm trying to move files from a directory to a shared drive that I have mapped. I know that using "XCOPY c:\etc.. z:\etc.. /Y" will copy everything from one place to another, but what I don't want to do is overwrite every file every time. Is there a way to copy just the files that are not located in the destination directory?

like image 314
Bigby Avatar asked Dec 16 '22 00:12

Bigby


2 Answers

solution 1 :

xcopy  /d/y

should work..........

enter image description here

solution 2

echo "No" | copy/-Y c:\source c:\Dest\

working. tested

2 folders have the same files , lets try to copy.

 C:\r\Roi>echo "No" | copy/-Y  . 2
.\DSpubring.pkr
Overwrite 2\DSpubring.pkr? (Yes/No/All): "No"
Overwrite 2\DSpubring.pkr? (Yes/No/All):
.\DSsecring.skr
Overwrite 2\DSsecring.skr? (Yes/No/All):
        0 file(s) copied.

lets create 1 new file

C:\r\Roi>copy con g.txt
sdfsdf
^Z
    1 file(s) copied.

lets copy :

C:\r\Roi>echo "No" | copy/-Y  . 2
.\DSpubring.pkr
Overwrite 2\DSpubring.pkr? (Yes/No/All): "No"
Overwrite 2\DSpubring.pkr? (Yes/No/All):
.\DSsecring.skr
Overwrite 2\DSsecring.skr? (Yes/No/All):
.\g.txt
        1 file(s) copied. <------------ one file only
like image 194
Royi Namir Avatar answered Mar 01 '23 22:03

Royi Namir


You can also do

robocopy /xc /xn /xo /s source destination 

Answer take from here.

like image 26
Himanshu Patel Avatar answered Mar 01 '23 23:03

Himanshu Patel