Computing.Net > Forums > Programming > Adding commands after echo

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Adding commands after echo

Reply to Message Icon

Name: Credo
Date: July 29, 2009 at 10:49:44 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: July 29, 2009 at 11:19:12 Pacific
Reply:

@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


0

Response Number 2
Name: Credo
Date: July 29, 2009 at 11:24:33 Pacific
Reply:

Thanks, I'll try it.

What does the

& setLocal EnableDELAYedExpansion

do?


0

Response Number 3
Name: Credo
Date: July 29, 2009 at 11:42:50 Pacific
Reply:

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!


0

Response Number 4
Name: Mechanix2Go
Date: July 29, 2009 at 12:17:26 Pacific
Reply:

!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


0

Response Number 5
Name: klint
Date: July 30, 2009 at 02:20:48 Pacific
Reply:

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.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Adding commands after echo

Dos: set help??????? www.computing.net/answers/programming/dos-set-help/11510.html

Office XP Deployment www.computing.net/answers/programming/office-xp-deployment/9200.html

batch file programming www.computing.net/answers/programming/batch-file-programming/17121.html