# Batch file doesn't execute properly



## tdbest (Apr 30, 2007)

I'm trying to get a batch file to simply get a file count, then execute a series of commands if the count is greater than 25000. The batch file works perfectly if I manually execute everything one at a time, but completely falls apart when executed as a batch.

Here's the batch file;

```
e:
del e:\count.txt
dir /a /b e:\spam > e:\count.txt
for /f "tokens=3,4" %F in ('find /c /v "" count.txt') do set count=%F
cd \
IF /I %COUNT% GEQ 25000 (goto true) else (goto false)

:true
echo Over 25,000 files found. Performing sub-spooling...
e:
cd \spam
for /f %F in ('echo %random%') do set spamfolder=%F
for /f %F in ('echo %spamfolder%') do mkdir spam%F
for /f %F in ('echo %spamfolder%') do move *.eml spam%F
del *.hdr /q
goto end

:false
goto end

:end
exit
```
Here's what happens when it's executed;

```
C:\>spam_subspool.bat

C:\>e:

E:\>del e:\count.txt

E:\>dir /a e:\spam 1> e:\count.txt
F was unexpected at this time.

E:\>for /f "tokens=3,4" F

E:\>
```
Any ideas why this is happening?


----------



## ZeRealBigBoss (Mar 17, 2007)

I can be wrong, too long ago that I batched, but shouldn't it be %%F ?

FOR /F ["options"] %%parameter IN ("Text string to process") DO command

http://www.ss64.com/nt/for_f.html


----------



## JohnWill (Oct 19, 2002)

Correct, you need two % in the batch file.


----------



## tdbest (Apr 30, 2007)

Yep, that was it. I guess I didn't RTFM hard enough...

"{%variable|%%variable} : Required. Represents a replaceable parameter. Use %variable to carry out for from the command prompt. Use %%variable to carry out the for command within a batch file. Variables are case-sensitive and must be represented with an alpha value, such as %A, %B, or %C."


----------

