Page 1 of 1

Batch File - For Loop Problems

Posted: 19 Jun 2009 09:55
by RealMarkP
I'm running a For loop that reads each entry from a file, does some manipulations and EXE executions and then stops. Here is the problem: I have more commands AFTER the For loop which never get executed. Can anyone offer any advice on this?

Here is some code:

Code: Select all

SET ECMArchData=ECM-OS-Arch.txt

ECHO - Loop Through Data In %ECMArchData%
FOR /F %%a IN (%ECMArchData%) DO (

   ECHO =================================
   ECHO - Creating %%a Dir
   IF NOT EXIST "ECM-%%a" (
      MKDIR "ECM-%%a"
   )
   
   ECHO - Copy %ECMOrigDir% To "ECM-%%a"
   XCOPY /E /Y /Q %ECMOrigDir% "ECM-%%a"

   ECHO - Do Some EXE Stuff *SNIP*
   
   ECHO - Moving Into "ECM-%%a"
   PUSHD "ECM-%%a"
      ECHO   - Executing FactoryPrep
      FactoryPrep.bat
   POPD
)

ECHO =================================
ECHO       Step 4.2 - THIS NEVER GETS EXECUTED
ECHO =================================

ECHO - Preparing CABBuilder
PUSHD FactoryPrep

   ECHO - Running CABBuilder
   CABBuilder.exe %CABBuilderCmdArgs%
POPD

Posted: 19 Jun 2009 10:20
by avery_larry
If you just run factoryprep.bat, it'll leave the current bat and go to that one.

Instead:

call factoryprep.bat

Otherwise you'll need to post the entire code as it may be in the exe portion.

Posted: 19 Jun 2009 10:41
by RealMarkP
Adding the CALL statement before calling the separate BAT file worked! Thanks!

Re: Batch File - For Loop Problems

Posted: 14 Jan 2022 06:53
by Jedininja
some things i noticed, you were trying to add ecm- to %%a before it was defined and also Defining %%a and applying %%a must happen on the same line. Echoing special characters causes a lot of crap, ~^=+*. use ---- for graphics.

Code: Select all

SET ECMArchData=ECM-OS-Arch.txt

FOR /F %%a IN (%ECMArchData%) DO ( IF NOT EXIST %%a (MD "ECM-%%a" & XCOPY /E /Y /Q %ECMOrigDir% "ECM-%%a") & PUSHD ecm-%%a
start FactoryPrep.bat
POPD
)

PUSHD FactoryPrep
CABBuilder.exe %CABBuilderCmdArgs%
POPD
~~ so ( MD "ECM-%%a" will make a folder named ecm-filename.txt then copy ECMOrigDir to ECM-%%a &then store in in popd, run factoryprep.bat call the stored var in popd)

and the end there i believe is trying to compress the file stored in popd ? i shall tinker with it when i get home, i have to make files and dir's to work out the pop/pushd. cool concept!

p.s. i totally skiped over post #3 there

Re: Batch File - For Loop Problems

Posted: 14 Jan 2022 11:31
by aGerman
Thread from 2009 :roll:

Re: Batch File - For Loop Problems

Posted: 14 Jan 2022 11:42
by Squashman
Jedininja wrote:
14 Jan 2022 06:53
some things i noticed, you were trying to add ecm- to %%a before it was defined and also Defining %%a and applying %%a must happen on the same line.
This statement is just wrong.

Re: Batch File - For Loop Problems

Posted: 15 Jan 2022 02:58
by Jedininja
Squashman wrote:
14 Jan 2022 11:42
Jedininja wrote:
14 Jan 2022 06:53
some things i noticed, you were trying to add ecm- to %%a before it was defined and also Defining %%a and applying %%a must happen on the same line.
This statement is just wrong.
i have personally had a lot of problems using special characters as graphic characters in echo statements, and i am admittedly super noob with for statements but i'm sure that without the usage of parenthesis the %%i's must be on the same line, i however forgot to type that, and no its not relevant to this post anyways. lol

Anyways, im not sure if i fully understand what this script was intended to do however, here is what i think it was intended to do.

Make a dir
copy folder suffixes from a file
mass make static prefix+suffix named folders
copy content from a second batch list to those folders
and then compress them

so iv been playing around with it all day attempting to figure out what it its and how to reduce it and this is where i am at right now.

Code: Select all

SET testvar1=%systemdrive%\temp\test2.txt & SET testvar2=%systemdrive%\temp2
FOR /F %%a IN (%testvar1%) DO (IF NOT EXIST %%a (MD %testvar2%\ECM-%%a) else (XCOPY /E /Y /Q %testvar1% %testvar2%\ECM-%%a))
REM call testvar.bat > makecab /v %testvar2%ECM-%%a)
REM TAR command may pipe
test2.txt is a list of stats from a character file arranged in a column.
the second set temp folder made all the pushd and popd commands aswell as changing the current drive unneeded
im now trying to figure out an archive command i can pipe %%i > archive to and hopefully defeat the need to make folders at all. :)