I'm trying to write a batch file that copies folders from one folder location to another, but only if they exist in a third folder.
That sounds confusing, I'll try again.
I have the following 3 folders:
- Updates
- Applications
- Previous Versions
Before updating the \Applications
subfolder structure with the [new version] \Updates
subfolder structure, I need to copy the \Applications
subfolder structure to the \Previous Versions
folder. Once that is complete then it needs to copy the Updates
subfolder structure to the /Applications
folder.
I got as far as the following:
Setlocal EnableDelayedExpansion
Set UpdtRoot=C:\Test\Updates
Set AppsRoot=C:\Test\Apps
Set PVerRoot=C:\Test\Previous Versions
FOR /d %%i IN ("!UpdtRoot!\*.*") DO xcopy "!AppsRoot!\%%~nxi" "!PVerRoot!\%%~nxi\" /e
This doesn't work though, it copies all the folders from AppsRoot into PVerRoot.
I need it to copy subfolders from AppsRoot
to PVerRoot
, but only if they exist in UpdtRoot
. I only need it to copy the folders and subfolders ONLY so no files at all.