Batch File - For Loop Problems

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
RealMarkP
Posts: 2
Joined: 19 Jun 2009 09:36

Batch File - For Loop Problems

#1 Post by RealMarkP » 19 Jun 2009 09:55

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

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 19 Jun 2009 10:20

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.

RealMarkP
Posts: 2
Joined: 19 Jun 2009 09:36

#3 Post by RealMarkP » 19 Jun 2009 10:41

Adding the CALL statement before calling the separate BAT file worked! Thanks!

Jedininja
Posts: 25
Joined: 11 Jan 2022 22:41
Location: CanafukpilesDa
Contact:

Re: Batch File - For Loop Problems

#4 Post by Jedininja » 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. 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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch File - For Loop Problems

#5 Post by aGerman » 14 Jan 2022 11:31

Thread from 2009 :roll:

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Batch File - For Loop Problems

#6 Post by Squashman » 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.

Jedininja
Posts: 25
Joined: 11 Jan 2022 22:41
Location: CanafukpilesDa
Contact:

Re: Batch File - For Loop Problems

#7 Post by Jedininja » 15 Jan 2022 02:58

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. :)

Post Reply