I have a problem with the script below.
I create this batch to retrieve each file existing on the directory. For each file I call a stored procedure to import the containing of the file in a sqlserver table.
While the file is importing i move it in a Archives directory and a continue the same process with the next file find in the first directory.
But i don't know why the batch processed only one file and exit without processing the other files existing in the directory.
Code: Select all
REM VARIABLE PART
REM ------------
for %%f in (%XMLDIRSERV%\*.xml /B/O:N) do call :treatement %%f
Goto :End
:treatement
SET Errfichier=0
SET ERRORLEVEL=0
SET fichier=%1
SET fichierExp='%1%'
setlocal enabledelayedexpansion
REM ******************************************************************************************
REM import code remark int the table EIO.dbo.t_upd_Import
REM ******************************************************************************************
for /f "delims=" %%a in ('sqlcmd -d%DB% -S%DBHost% -U%UserDB% -P%PasswdDB% -Q "EXEC EIO.dbo.Proc_Import_XML %fichierExp%" ') DO (
set MessageSQL=%%a
Echo MessageSQL %MessageSQL%
Echo ERRORLEVEL %ERRORLEVEL%
IF %ERRORLEVEL% NEQ 0 (
Echo test %ERRORLEVEL%
move %fichier% %XMLDIRSERV%\ERR
SET Errfichier=1
)
)
REM ******************************************************************************************
REM Updt informations previously retrieved
REM ******************************************************************************************
@SET CodeRetour=0
echo Errfichier %Errfichier%
rem IF %Errfichier% EQ 0 (
for /f "delims=" %%i in ('@"%JAVA_HOME%\bin\java" com.crn.pi.export.impl.run.Importer V:\Import\XML\Update_element.cfg localhost Administrator eio %UserDB% %PasswdDB% EIO %DBHost%') do SET Message=%%i
REM If not successfull, exit 1
echo "%Message%"=="%Message:took=%"
If "%Message%"=="%Message:took=%" (
SET CodeRetour=1
Goto :End
)
REM If Error Nodes != 0 in at least one log, exit 2
for %%x in (%LOGDIR%\*_log.xml) do set /a count+=1
for /f %%i in ('type %LOGDIR%\*_log.xml ^|find /c "Error Nodes=""0"') do SET error=%%i
IF NOT %error%==%count% (
SET CodeRetour=2
move %%f %XMLDIRSERV%\ERR
) ELSE (
move %fichier% %XMLDIRSERV%\ARCHIVES
)
rem )
:End
echo %CodeRetour%
rem pause
exit %CodeRetour%