2

I have a folder on my computer that I want to schedule (using task scheduler) the backup every day. What I want to do is, if the destination folder already contains the folder (including the subfolder and files) from the source path, it will be skipped and continue copying the other folders that are not yet on the destination folder (I don't want to overwrite existing folders or subfolders or even the files). How could I do that to my batch file?

e.g. source folder contains: Folder1 Folder2 Folder3

destination folder contains: Folder1 (same folder on the source) Folder2 (same folder on the source)

The command will copy the Folder3 only.

Daryll
  • 77
  • 1
  • 2
  • 10
  • This has been answered before: http://stackoverflow.com/questions/13314433/batch-file-to-copy-directories-recursively – Hans Sep 01 '13 at 20:12
  • I don't think is the same question. OP want to Exclude from copy the folders that are already present in the destination. – PA. Sep 01 '13 at 20:53
  • I posted answer here how to copy without xcopy and robocopy: https://stackoverflow.com/a/76749027/17765118 – ildarin Jul 23 '23 at 16:38

2 Answers2

9

This will mirror the source to the target and skip files that already exist, but will also remove files (from the target) that no longer exist in the source - Vista and higher have Robocopy. XP can download it.

robocopy "c:\source" "d:\target" /mir

or a UNC path

robocopy "\\server1\share\" "\\server2\\share2" /mir
foxidrive
  • 40,353
  • 10
  • 53
  • 68
1

There are various backup and copy utilities that can do this, and many other options, for you.

However, just for your stated requirement, it's easy to write a BAT solution...

Read HELP FOR, and then try this simple FOR command

for /D %%a in (*) do (
  if not exist %dest%\%%a (
    echo xcopy /s %%a %dest%
  )
)

verify the output and then remove the ECHO

PA.
  • 28,486
  • 9
  • 71
  • 95