locked
Exiting a Batch File For Loop RRS feed

  • Question

  • I am fairly new to windows batch files and have a problem with the following script :

    rem @ echo off
    cls

    set vendor=SHAMFOOD
    set dr=Y:\BPEL\Enterprise\kevin\
    set filnm=Wahoo*.txt
    set mdl=_INV_
    set ext=.txt
    set FOUND1=F

    FOR /R %dr% %%G IN (%filnm%) DO (
    rem   echo %%G
       set FOUND1=F
       FOR /F "tokens=3 delims=~"  %%H IN (%%G) DO (
             IF "%FOUND1%"=="F" (
                  set filenam=%vendor%%mdl%%%H%ext%
                  set FOUND1=T
             )
        )
        copy %%G test\%filenam%
     )

    rem echo ren confirm_%NBR%.txt confirm_%item%.sr >>%1.txt
    rem echo %filenam%


    I have a For Loop with in another for loop and I want to exit the inner one after 1 pass or at least not process any of the lines after the first one read.  The code above is not working.  The variable FOUND1 is not getting reset to "T".  Can anyone tell me what is wrong with my code?  Any HELP would be appreciated.
    Sunday, April 27, 2008 9:33 PM

All replies

  • What Are You Trying To Achieve With This Batch

    IF You Only want To Process First Line OF Text File Why Not Take It Into A Variable
    set /p firstline=<myfile.txt
    Sunday, May 25, 2008 9:17 AM
  • You need SETLOCAL ENABLEDELAYEDEXPANSION at the top of the file after @ECHO OFF
    Also, you need to changed %FOUND1% to !FOUND1! and then it should work.
    Monday, August 11, 2008 2:17 PM