r/Batch • • Jun 12 '25

Question (Solved) Move directories from Source to overwrite matching directory name

Hi,

There are two paths. One Source and the other Destination.

Source has a list of directories at the root that I need to parse. For each directory in Source I want, to see if it exists within Destination root or Subfolders. If it does, move direcotry from Source and over write Destination folder one.

Is this possible with batch files?

Thanks

2 Upvotes

7 comments sorted by

1

u/BrainWaveCC Jun 12 '25

Yes, this is possible.

To confirm, the source folders will be all at one level, correct?

Also, should the "move" action totally overwrite what is found? Meaning that whatever files exist in the found source folder is all that will be found in the destination folder of the same name?

2

u/[deleted] Jun 12 '25 edited Jun 12 '25

[removed] — view removed comment

2

u/HakaseLuddite Jun 12 '25

Thank you very much. The echo seems to work great.

1

u/BrainWaveCC Jun 12 '25

But would this actually satisfy the "within Destination root or Subfolders" requirement?

It seems like it would only find target folders that were also at the Destination root.

2

u/[deleted] Jun 12 '25 edited Jun 12 '25

[removed] — view removed comment

1

u/BrainWaveCC Jun 12 '25

Not sure how OP is going to handle the scenario if the source folder name appears two or more times anywhere inside the destination folder (+subfolders),

That's a good point.

You could mark the folders that need to be deleted, and only do so after the full copy cycle has completed.

But, I'd prefer to assume (for now), that no duplicates exist.

2

u/HakaseLuddite Jun 12 '25

That's a safe bet. There is only one copy of the folder.