You should keep in mind that I'm only as good as your specifications and your requirement.
Code: Select all
@echo off &setlocal enabledelayedexpansion
:: SETTINGS
set "root=d:\mine" &REM root folder
set /a numXmls=50 &REM number of .xml files placed in a single sub folder
set "dateOrder=y m d" &REM order of year, month and day in %date% (space separated)
set "dateSeparator=-" &REM separator of year, month and day in %date%
:: CALCULATE PREDEFINED VARIABLES
set "xDate=%date%"
for /f "tokens=2" %%i in ("%xDate%") do set "xDate=%%i"
for /f "tokens=1-3" %%a in ("%dateOrder%") do (
for /f "tokens=1-3 delims=%dateSeparator%" %%d in ("%xDate%") do (
set /a %%a=10000%%d%%10000,%%b=10000%%e%%10000,%%c=10000%%f%%10000
)
)
set /a m=10%m%, d=10%d%
set "basename=EN%m:~-2%%d:~-2%"
:: WAIT FOR USER INPUT
:loop
set /p "i=Sequence starting from number: "
echo("%i%"|findstr /vrxc:"\"[0-9][0-9]*\"" >nul &&goto :loop
set /a i-=1
:: MOVE .XML AND .TIFF FILES, WRITE SUMMARY REPORT
for /f "tokens=1* delims=:" %%a in ('dir /a-d /b /on "%root%\mdata\*.xml"^|findstr /n .') do (
set /a n=%%a %% numXmls - 1
if !n!==0 (
if defined name (
>>"!txtName!" echo ==============================================================================
>>"!txtName!" echo(
>>"!txtName!" echo Total XML Files: !totalXML!
>>"!txtName!" echo Total IMG Files: !totalIMG!
)
set /a i+=1, totalXML=0, totalIMG=0, xmlCount=0
set "j=00!i!"
set "name=%root%\%basename%!j:~-3!"
set "txtName=!name!\%basename%!j:~-3!.txt"
md "!name!" 2>nul
>"!txtName!" echo ==============================================================================
>>"!txtName!" echo Count XML Files Image Count
)
move "%root%\mdata\%%~b" "!name!\"
set /a imgCount=0, totalXML+=1, xmlCount+=1
set "fileName=%%~nb"
for /f "delims=" %%c in ('dir /a-d /b /on "%root%\images\!fileName:~,-1!c*.tif?"') do (
move "%root%\images\%%~c" "!name!\"
set /a imgCount+=1, totalIMG+=1
)
call :add_spaces "!xmlCount!" 7 strNum
call :add_spaces "%%~b" 60 strName
>>"!txtName!" echo !strNum!!strName!!imgCount!
)
if defined name (
>>"%txtName%" echo ==============================================================================
>>"%txtName%" echo(
>>"%txtName%" echo Total XML Files: %totalXML%
>>"%txtName%" echo Total IMG Files: %totalIMG%
)
goto :eof
::SUB ROUTINE FOR CREATING A FIXED STRING LENGTH
:add_spaces stringIn lengthIn newStringOut
setlocal
set "spaces= "
set "out=%~1%spaces%"
set "out=!out:~,%~2!"
endlocal &set "%~3=%out%"
goto :eof
Regards
aGerman