1 Replies - 2366 Views - Last Post: 16 May 2012 - 10:15 AM Rate Topic: -----

#1 scienalc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 22-July 11

batch script - how to merge contents of folders (not just copy)

Posted 16 May 2012 - 03:26 AM

Hi guys,

I need to write an batch script that should copy folders from location A(source) to location B(destination). In location B some of those files and folders already exist, so the existing ones should be overwritten but the other files should be preserved.

I tried to use XCOPY and its arguments to accomplish that, but all I got is that this overwrote entire folders, that is the folder in location B was entirely "replaced" by the same folder in location A, although it's intended to only be merged.

Do you have any suggestions?

I should point out that by this way ca. 18,000 files in 2,500 folders should be merged with an even larger directory (27,000 files in 4,000 folders) which has a very similar structure, taking in account that some of the source-folders need to excluded from the merge. So I guess that file by file operations are not recommended? That's why I tried the "whole folder merge" approach.

Thanks a lot

PS I'm using windows 7, so the merge I'm talking about is the one that you get when copy a folder to a destination which contains the same folder name and then choose "Merge" those folders and "Copy and Replace" for the files.

Is This A Good Question/Topic? 0
  • +

Replies To: batch script - how to merge contents of folders (not just copy)

#2 mojo666  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 352
  • View blog
  • Posts: 770
  • Joined: 27-June 09

Re: batch script - how to merge contents of folders (not just copy)

Posted 16 May 2012 - 10:15 AM

I tried xcopy "c:\A" "c:\B" /e /y and it worked fine. Subfolders that were not present in B were created. Files that were in subfolders of B but not A were not touched. Files that were not in B's hierarchy were created. Files that were in both were overwritten with A's version. This is characteristic of a merge.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1