EDIT fixed the 'copy all files' issue.
This should do the following: (change c:\cde and c:\abc)
1) copy 9 most recent files from the folder
2) merge them all into one file called foldername-HHMMSS (from the time variable)
3) The foldername-HHMMSS file is created in the c:\ABC folder
4) remove the 9 copied files
5) repeat for each folder
@echo off
set "source=D:\ABC"
set "target=C:\files\CDE"
setlocal enabledelayedexpansion
md "%target%" 2>nul
for /d /r "%source%" %%a in (*) do (
pushd "%%a"
set num=0
for /f "delims=" %%b in ('dir /o-d /b /a-d') do (
set /a num+=1
if !num! LSS 10 copy "%%b" "%target%" >nul
)
set t=!time!
set t=!t:~0,2!!t:~3,2!!t:~6,2!
copy "%target%\*.*" "%source%\%%~nxa-!t!" >nul
echo "%source%\%%~nxa-!t!" created from "%%a"
if defined target del "%target%\*.*?"
popd
)
pause