Batch - Browse directory not work

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Debian
Posts: 3
Joined: 06 Apr 2020 04:00

Batch - Browse directory not work

#1 Post by Debian » 06 Apr 2020 05:18

Hi everybody

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%


Debian
Posts: 3
Joined: 06 Apr 2020 04:00

Re: Batch - Browse directory not work

#2 Post by Debian » 06 Apr 2020 09:25

Someone can help me to solve the problem ? :mrgreen:

OJBakker
Expert
Posts: 29
Joined: 12 Aug 2011 13:57

Re: Batch - Browse directory not work

#3 Post by OJBakker » 07 Apr 2020 01:45

Your subroutine :treatment is missing the 'end subroutine' command.
This causes processing of :treatment to continue with the command in :end, so processing stops with the''exit %CodeRetour%' command.

Add 'exit/B' or 'goto :eof' at the end of the subroutine to correct this.

Debian
Posts: 3
Joined: 06 Apr 2020 04:00

Re: Batch - Browse directory not work

#4 Post by Debian » 07 Apr 2020 02:28

OJBakker you're a genuis thank you very much !

Post Reply