@echo off
setlocal enabledelayedexpansion
echo UpdateAllSequences - Running all UpdateSequences.bat files in submodule folders...
echo.

echo Searching for submodule folders and UpdateSequences.bat files...
echo.

REM Find all submodule folders and check for UpdateSequences.bat
set /a count=0
set /a found=0

echo Found the following submodule folders with UpdateSequences.bat:
for /d %%S in (*) do (
    if exist "%%S\UpdateSequences.bat" (
        echo   - %%S
        set /a found+=1
    )
)

if !found!==0 (
    echo No submodule folders with UpdateSequences.bat found!
    echo.
    echo Note: This script looks for UpdateSequences.bat files in immediate subdirectories.
    echo Make sure you're running this from the project root where submodules are located.
    pause
    exit /b 1
)

echo.
echo Found !found! submodule folders with UpdateSequences.bat files.
echo.
echo Starting execution...
echo.

REM Execute each UpdateSequences.bat found in submodule folders
for /d %%S in (*) do (
    if exist "%%S\UpdateSequences.bat" (
        set /a count+=1
        echo [!count!/!found!] Running UpdateSequences.bat in %%S...
        pushd "%%S"
        call "UpdateSequences.bat" < NUL
        set "rc=!errorlevel!"
        popd
        if !rc!==0 (
            echo   Completed: %%S (SUCCESS)
        ) else (
            echo   Completed: %%S (FAILED - RC=!rc!)
        )
        echo.
    )
)

echo.
echo Operation completed. Successfully executed !count! UpdateSequences.bat files.
echo.
echo Note: Check individual _CURRENT\_UpdateSequences.log files in each submodule for details.
pause
