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

18
2014-05
  • awe

    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.

  • Answers
  • Uninspired
    echo n|xcopy "[source]" "[destinaton]" 
    

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

  • Pinger

    Robocopy - auto skip files already in the destination

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

  • Stefan Seidel

    This command solved this for me:

    XCOPY *.ZIP /D C:\DESTINATION
    
  • awe

    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.


  • Related Question

    windows - Copying all files from multiple folders to a single folder
  • Alex

    I have about 65000 files in 3000 folders in c:\foo\root (ie, c:\foo\root\folder1, c:\foo\root\folder2 etc). I want to copy all of those files to a single folder c:\All\.

    I've tried Robocopy but it just does a full copy (directories included). If during the copying process it comes across files with the same name, I need it to rename the new one as temp(2).file or similar, not just ignore it or overwrite.

    Anyone know how to do this with a batch file/command prompt? Even some C# would be great.


  • Related Answers
  • therube

    Not thinking clearly ATM, so this is a round-about method ...

    If you were to archive the tree (using a non-compress method would be faster) you could work it in two ways. Archive the tree (so subdirectories included) & extract with an 'E' (Extract) rather then with an 'X' (eXtract files with full path), the extracted files would be placed into a single directory. Other way to do the same would be on archive creation, to tell it to "exclude paths from names". Then the created archive would be barren of paths, i.e. all files stored in a single directory in the archive, so when extracted, they would extract that way too. (Thinking the former method makes more sense.)

    (ARJ can do this. Would think that 7z & RAR & ZIP could too?)

    "Flatten" was a word I was trying to think of earlier. And with that, a backup/synchronization program likely can be set to "flatten" a directory structure.

    So other thoughts ... Tar & DD? Maybe that will help others come up with a better answer that I'm not thinking of ATM.

    (Been a long time since I've used Tar, so I may off base, but something in the nature of...)

     tar -cvf c:/foo/roo | tar -xvf -
    

    An archiver & backup/synchronizer should be able to handle any dups in an automated fashion.
    ARJ can. Don't know about tar?