You can use the FOR /D command to loop through the directories in a path:
FOR /D %%I IN (C:\Customers\*) DO (
REM %%I is "C:\Customers\FolderA", etc.
robocopy.exe /E "%%I\FolderB\files" "C:\FolderB\files"
)
Let's assume the directory C:\Customers contains:
- A. Datum Corporation
- AdventureWorks Cycles
- Alpine Ski House
- Awesome Computers
- Baldwin Museum of Science
- Blue Yonder Airlines
If we run this simple command script:
FOR /D %%I IN (C:\Customers\*) DO (
ECHO %%I
)
We get this output:
C:\Customers\A. Datum Corporation
C:\Customers\AdventureWorks Cycles
C:\Customers\Alpine Ski House
C:\Customers\Awesome Computers
C:\Customers\Baldwin Museum of Science
C:\Customers\Blue Yonder Airlines
So taking that a step further, this command script:
FOR /D %%I IN (C:\Customers\*) DO (
robocopy.exe /E "%%I\FolderB\files" "C:\FolderB\files"
)
Would run the following commands in sequence:
robocopy.exe /E "C:\Customers\A. Datum Corporation" "C:\FolderB\files"
robocopy.exe /E "C:\Customers\AdventureWorks Cycles" "C:\FolderB\files"
robocopy.exe /E "C:\Customers\Alpine Ski House" "C:\FolderB\files"
robocopy.exe /E "C:\Customers\Awesome Computers" "C:\FolderB\files"
robocopy.exe /E "C:\Customers\Baldwin Museum of Science" "C:\FolderB\files"
robocopy.exe /E "C:\Customers\Blue Yonder Airlines" "C:\FolderB\files"
The output, of course, would be the result of each robocopy command.