Adding commands after echo

July 29, 2009 at 10:49:44
Specs: Windows XP
Hello everyone, I was wondering if it's possible to add command code to be run on the same line as an echo.

IE:

ECHO Current number of lines: TYPE C:\files.txt

so I want to display "6 Downloaded"
6 being the value in files.txt.

I've tried this:

SET numfiles=0
DIR /a-d | FIND /c /i ".PRN" > NUMfiles.cnt	
SET /P numfiles=<NUMfiles.cnt
ECHO %numfiles%  Downloaded.>> C:\LOG\LOG_%curdate%.log

But It WILL NOT display the value pulled from the file.. I CAN'T FIGURE OUT WHY! The method works, and there is a value in the file - but for some reason when I try to write the output to the log file there's no number. All I get is:

Downloaded.

If anyone can tell my WHY it's not writing the value to the variable - and maybe another work around.

Thanks in advance.


See More: Adding commands after echo

Report •


#1
July 29, 2009 at 11:19:12
@echo off & setLocal EnableDELAYedExpansion

set num=

for /f "tokens=* delims= " %%a in ('dir/b/a-d *.prn') do (
set /a num+=1
)
echo number of prn files !num!


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
July 29, 2009 at 11:24:33
Thanks, I'll try it.

What does the

& setLocal EnableDELAYedExpansion

do?


Report •

#3
July 29, 2009 at 11:42:50
Thanks M2, that worked great!

I just don't understand why you used the "!" instead of the "%" for variables, and I know it didn't work until I added

& setLocal EnableDELAYedExpansion

to the @echo off...

Thanks again!


Report •

Related Solutions

#4
July 29, 2009 at 12:17:26
!VAR! within setlocal clears the VAR when the bat quits. So you don't need to clean up.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#5
July 30, 2009 at 02:20:48
I'd just like to add, when I tested Credo's original batch file, it
worked. I don't know why it didn't work for you. Perhaps you have
misspelt a variable in your batch file but spelt it correctly in your
post.

Report •


Ask Question