Page 1 of 1

Multiple FOR LOOP

Posted: 09 Apr 2010 08:46
by six1zero
Hi
I've go 2 FOR LOOP.
The Batch do the first loop only one time and pass automatically to the second.
Do you know why? Where is the mistake?

@echo off
REM -- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION

SET ELS_DRIVE=%ELSHOMEDIRECTORY%\Test
SET SPOOLTV=%ELS_DRIVE%\SpoolTV
SET MATHRES=%ELS_DRIVE%\MathRes
SET FILE_IOP=InvestmentOrderProtocol
SET FILE_NOTICE=Notice_
SET FILE_MATHRES=MathRes
SET FILE_SUFFIX=.ps
SET SPOOLEDSTUFFTV=%ELS_DRIVE%\SpooledStuffTV
SET PRINTER_IP=%PRINTER_IP%
SET PRINTER_DESCRIPTION=%PRINTER_DESCRIPTION%

rem TODAY
SET dd=%DATE:~0,2%
SET mm=%DATE:~3,2%
SET yyyy=%DATE:~6,4%
rem SET dd=dd
rem SET mm=mm
rem SET yyyy=yyyy

REM Verify if SpooledStuff directory exist, if not exist create a new directory tree
IF NOT EXIST %SPOOLEDSTUFFTV%\%yyyy% mkdir %SPOOLEDSTUFFTV%\%yyyy%
IF NOT EXIST %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm% mkdir %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm%
echo %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm%

%ELS_DRIVE%
cd %SPOOLTV%

echo.
echo Convertering PostScript Document
%ELS_DRIVE%\EverlastingLibrary\Tools\PSConverter %SPOOLTV%
echo.
echo PSConverter post

echo.
echo ------------ Print Invest Order Portfolio File
for %%i in (%FILE_IOP%*%FILE_SUFFIX%) do CALL :FILE_IOP %%i

:FILE_IOP
SET myTempFile=%1
IF "%myTempFile%"=="" GOTO:FILE_NOTICE_PART
echo.

lpr -S %PRINTER_IP% -P "%PRINTER_DESCRIPTION%" %myTempFile%
lpr -S %PRINTER_IP% -P "%PRINTER_DESCRIPTION%" %myTempFile%
echo Printed 2 copies of: %myTempFile%

echo Move file %myTempFile% to %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm%
move /Y %SPOOLTV%\%myTempFile% %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm%


:FILE_NOTICE_PART
echo.
echo ------------ Print Notice File
for %%i in (%FILE_NOTICE%*%FILE_SUFFIX%) do CALL :FILE_NOTICE %%i

:FILE_NOTICE

SET myTempFile=%1
IF "%myTempFile%"=="" GOTO:EOF
echo.

lpr -S %PRINTER_IP% -P "%PRINTER_DESCRIPTION%" %myTempFile%
lpr -S %PRINTER_IP% -P "%PRINTER_DESCRIPTION%" %myTempFile%
echo Printed 2 copies of: %myTempFile%

echo Move file %myTempFile% to %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm%
move /Y %SPOOLTV%\%myTempFile% %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm%

Re: Multiple FOR LOOP

Posted: 09 Apr 2010 12:36
by jeb
Hi six1zero,

I suppose the problem is, that your first for-loop never call the :FILE_IOP, the :FILE_IOP is reached directly.
You should add some goto :eof


Code: Select all

for %%i in (%FILE_IOP%*%FILE_SUFFIX%) do (
  echo calling FILE_IOP
  CALL :FILE_IOP %%i
)
goto :eof

:FILE_IOP
...
goto :eof


jeb

Re: Multiple FOR LOOP

Posted: 12 Apr 2010 00:55
by six1zero
Hi Jeb

my first loop call correctly the FILE_IOP part but instead of continue to loop until finish to process all files, the program go ahead to the second loop.
The second loop process the 1 file and go ahead to the third... the third...to quarter...
If I have only the first loop it works correctly.
it's very strange.

Re: Multiple FOR LOOP

Posted: 12 Apr 2010 02:22
by jeb
Hi six1zero,

there are no return's ( goto :eof) at the end of your functions.

Code: Select all

@echo off
REM -- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION

SET ELS_DRIVE=%ELSHOMEDIRECTORY%\Test
SET SPOOLTV=%ELS_DRIVE%\SpoolTV
SET MATHRES=%ELS_DRIVE%\MathRes
SET FILE_IOP=InvestmentOrderProtocol
SET FILE_NOTICE=Notice_
SET FILE_MATHRES=MathRes
SET FILE_SUFFIX=.ps
SET SPOOLEDSTUFFTV=%ELS_DRIVE%\SpooledStuffTV
SET PRINTER_IP=%PRINTER_IP%
SET PRINTER_DESCRIPTION=%PRINTER_DESCRIPTION%

rem TODAY
SET dd=%DATE:~0,2%
SET mm=%DATE:~3,2%
SET yyyy=%DATE:~6,4%
rem SET dd=dd
rem SET mm=mm
rem SET yyyy=yyyy

REM Verify if SpooledStuff directory exist, if not exist create a new directory tree
IF NOT EXIST %SPOOLEDSTUFFTV%\%yyyy% mkdir %SPOOLEDSTUFFTV%\%yyyy%
IF NOT EXIST %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm% mkdir %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm%
echo %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm%

%ELS_DRIVE%
cd %SPOOLTV%

echo.
echo Convertering PostScript Document
%ELS_DRIVE%\EverlastingLibrary\Tools\PSConverter %SPOOLTV%
echo.
echo PSConverter post

echo.
echo ------------ Print Invest Order Portfolio File
for %%i in (%FILE_IOP%*%FILE_SUFFIX%) do CALL :FILE_IOP %%i
goto :eof

Code: Select all


:FILE_IOP
SET myTempFile=%1
IF "%myTempFile%"=="" GOTO:FILE_NOTICE_PART
echo.

lpr -S %PRINTER_IP% -P "%PRINTER_DESCRIPTION%" %myTempFile%
lpr -S %PRINTER_IP% -P "%PRINTER_DESCRIPTION%" %myTempFile%
echo Printed 2 copies of: %myTempFile%

echo Move file %myTempFile% to %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm%
move /Y %SPOOLTV%\%myTempFile% %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm%
goto :eof

Code: Select all


:FILE_NOTICE_PART
echo.
echo ------------ Print Notice File
for %%i in (%FILE_NOTICE%*%FILE_SUFFIX%) do CALL :FILE_NOTICE %%i
goto :eof

Code: Select all


:FILE_NOTICE

SET myTempFile=%1
IF "%myTempFile%"=="" GOTO:EOF
echo.

lpr -S %PRINTER_IP% -P "%PRINTER_DESCRIPTION%" %myTempFile%
lpr -S %PRINTER_IP% -P "%PRINTER_DESCRIPTION%" %myTempFile%
echo Printed 2 copies of: %myTempFile%

echo Move file %myTempFile% to %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm%
move /Y %SPOOLTV%\%myTempFile% %SPOOLEDSTUFFTV%\%yyyy%\%yyyy%.%mm%
goto :eof

jeb

Re: Multiple FOR LOOP

Posted: 13 Apr 2010 02:29
by six1zero
Hi Jeb

you are right!

Thank you very much for your suggestion. Now it works!

six1zero