@echo off
setlocal enabledelayedexpansion
for %%A in (*.bat) do (
for /f "delims=" %%B in ("%%A") do set fname=%%~nB
for /f "delims=" %%C in ("%%A") do set fextn=%%~xC
for /f "tokens=1* delims=_" %%D in ("!fname!") do set folname=%%D
echo folder name !folname!
echo.
xcopy /Y "E:\folder1\folder2\!folname!\folder3\*.jpg" "G:\folder1\folder2\spi-!folname!\folder3"
xcopy /Y "E:\folder1\folder2\!folname!\folder3\*.tiff" "G:\folder1\folder2\spi-!folname!\folder3"
xcopy /Y "E:\folder1\folder2\!folname!\folder3\*.eps" "G:\folder1\folder2\spi-!folname!\folder3"
xcopy /E /Y "E:\folder1\folder2\!folname!\folder3\*" "G:\folder1\folder2\spi-!folname!\folder3"
)
echo Finished
pause