Isso deve fazer o trabalho:
@ECHO OFF
SETLOCAL EnableDelayedExpansion
REM **************************************************
SET source_dir=C:\folder1
SET target_dir=C:\folder2
SET wildcard=obsolete
REM **************************************************
FOR /D /R %%G IN ("%source_dir%") DO (
SET "folder_name=%%G"
ECHO !folder_name! | FINDSTR /R "%wildcard%" >nul && CALL :copy
)
ECHO. & ECHO. & ECHO. & ECHO. & ECHO. & ECHO Done^^!
PAUSE
EXIT
:copy
SET target_folder_name=!folder_name:%source_dir%\=!
SET endbit=!target_folder_name:*%wildcard%=!
SET target_folder_name=!target_folder_name:%endbit%=!
SET endbit=!folder_name:*%wildcard%=!
SET folder_name=!folder_name:%endbit%=!
ROBOCOPY "!folder_name!" "%target_dir%\!target_folder_name!" /E
EXIT /B
O wildcard
faz distinção entre maiúsculas e minúsculas, a menos que você adicione a opção /I
a FINDSTR
:
ECHO !folder_name! | FINDSTR /I /R "%wildcard%" >nul && CALL :copy