Link to home
Start Free TrialLog in
Avatar of mousemat24
mousemat24

asked on

Display variable results form a batch file?

Hi there

Wonder if you can help me?

I have the following batch code (windowsXP)

set Files=attrib.exe /s c:\data\*.* |find /c /v ""
echo the value of Files is :%Files%

nFiles should display 11, but on the echo the value of nFiles is :%Files% line I'm getting 0

Can someone please tell me why this isnt working

Also

I have a filename called 001_004_test.xml

How do I get the value 004 and store that in a variable

Thanks
mosuemat24
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can of course change the "echo result is %%a" to "set files=%%a" in the first command to add it to a variable.  

The dir command returns all XML files in bare format (filename only) through all subdirs and excludes showing directory names (/a-d).  This is parsed using for by using the ' ' characters around it.  The for command splits the line at each space or comma by default and runs the command after the do for each line found in the output -- in this case the output is one line with the number on which is pulled out as the first token on the line.

Same sort of thing for the second question.  Sets the delimiter to _ and pulls the second token off the line.
Avatar of mousemat24
mousemat24

ASKER

Thank you for all your help!! that worked
No problem!

Steve