Batch file to copy all .zip files from one path to a different path comparing parent folder names [closed]

I'm trying to write a batch script to do the following:

I have many folders inside path "C:\FTP" For example "Folder1" "Folder2". Each folder may have a .zip file or may not. I'm looking to find a way to copy these .zip files to destination "D:\FTP" that also includes same folder names "Folder1", "Folder2". If the destination doesn't have a folder with the same name then it should create the missing folder and copy the .zip files from source as well.

Anyone has any idea how can i do that? Your help is really appreciated.


Solution 1:

You can use robocopy (standard with windows) using the /MIR option (mirror; copies all subdirectories, and PURGES files in the destination that are not in the source).

It supports wildcards so *.zip would work.

So robocopy c:\source d:\destination *.zip /MIR /v /l would probably work.

  • /v is verbose logging

  • /l is list only for testing

There are flags to exclude files and empty directories.

Documentation