Is it possible to copy a set of files, but automatically skip if file already exists?

37,978

Solution 1

The problem is solved by using robocopy and use the /M option to copy only files with the archive flag set, and then clear it.

robocopy /M *.zip c:\destination

In this article on wikipedia you see that this is actually very similar to what the archive flag is intended for in the first place.

Solution 2

This command solved this for me:

XCOPY *.ZIP /D C:\DESTINATION

Solution 3

echo n|xcopy "[source]" "[destinaton]" 

Check out the various arguments for xcopy to tailor for your particular use

Solution 4

Robocopy - auto skip files already in the destination

ROBOCOPY \some\folder c:\destination *.zip /S

Share:
37,978

Related videos on Youtube

awe
Author by

awe

I am a senior software developer. I am interested in .NET programming (C#, VB), web programming (ASP.NET, Javascript) and GUI design. The chat room I most frequently visit is Musical Practice & Performance.

Updated on September 17, 2022

Comments

  • awe
    awe over 1 year

    I know that the copy command has an option to automatically replace a file if it already exists, but I want to know if it is a way to copy the files only if they not already exist (/Y). I do not know the actual file names in the batch code, as I copy from the source using wildcards in the copy command:

    copy *.zip c:\destination
    

    The reason I want this instead of automatic overwrite is that the files are large, and to skip existing would save a lot of execution time. It is done over a network share, so copying this amount of data can take a while...

    Additional info:
    This is a batch job that runs a backup thing to copy zip files from my computer to a shared server, and in case the batch job didn't finish for some reason (only some of the zip files copied), I need to run the batch again, but only for those zip files that wasn't copied before.

  • awe
    awe over 13 years
    I found no option to skip if copied files already exist on destination.
  • indianwebdevil
    indianwebdevil over 13 years
    How does setting setting Archive attribute and reseting it would help ?
  • bdukes
    bdukes over 11 years
    The Robocopy documentation says that /s is for copying subdirectories, not auto-skip...
  • deed02392
    deed02392 almost 11 years
    I resorted to a hardware solution to this issue i.imgur.com/c1kVF7r.jpg
  • Xonatron
    Xonatron over 10 years
    What @bdukes said is true: "/S :: copy Subdirectories, but not empty ones" and "/E :: copy subdirectories, including Empty ones"
  • Xonatron
    Xonatron over 10 years
    Can you explain it? It's using /D for date: "/D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time." But this does not work if the sources hasn't changed.
  • awe
    awe over 10 years
    @deed02392: Although I like your solution, in my case the batch job will be started as a scheduled task, and it would be tricky to get the physical setup to happen automatically at a scheduled time. It would have to be a robot doing it perhaps.
  • awe
    awe over 10 years
    @nepsdotin: Se my answer for details.
  • frostymarvelous
    frostymarvelous about 9 years
    I would accept this answer. if the source file has not changed, it won't copy it. serves your purpose after all, if the file has changed, you would want to copy the newer version wouldn't you? @awe