windows - batch file to copy files from one folder to another

17
2014-05
  • queueoverflow

    My scanner software puts it's file into YYYY_MM_DD subfolders in C:\Dokumente und Einstellungen\Enrico\Eigene Dateien\Eigene Bilder\MP Navigator EX. The files are all JPEG files.

    Now I need to copy them out of the virtual machine, into a shared drive which is called E:.

    I would like to copy the subfolders into the shared drive, so that I have those date folders there. If a new picture is added to today's folder, it should be copied as well.

    On Linux, I would just use rsync -avE for this.

    How can I do this with a plain batch file in XP and 7?

  • Answers
  • Dennis

    You can use xcopy to copy entire directories (including subdirectories).

    The syntax is:

    xcopy source destination /S
    

    where the /S switch includes non-empty directories (/E copies empty directories as well).

    There are a couple of switches that serve as a backup solution:

    • /M copies only changed files (archive attribute set) and unsets the attribute.

    • /D copies only those files whose source time is newer than the destination time.

  • Shadok

    Use Robocopy which is the microsoft equivalent to rsync.
    To get the same result as rsync -avE /source /dest use the following command:

    robocopy source dest /e
    

    To run rsync -avE --delete you can directly use robocopy /mir.


  • Related Question

    windows - Is it possible to copy a set of files, but automatically skip if file already exists?
  • 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.


  • Related 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.