Solved

Display variable results form a batch file?

Posted on 2007-03-27
4
482 Views
Last Modified: 2013-12-29
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
0
Comment
Question by:mousemat24
  • 3
4 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 18799514
You can't do it the way you have there but you can do similar with the for command:

@echo off
for /f "tokens=1" %%a in ('dir /s /b /a-d *.xml ^| find /c /v ""') do echo Result is %%a

for the second half

@echo off
for /f "tokens=2 delims=_" %%a in ("001_004_test.xml") do echo %%a & set myresult=%%a

To run these from the command line use single % instead of double

hth

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18799541
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.
0
 

Author Comment

by:mousemat24
ID: 18800044
Thank you for all your help!! that worked
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18800203
No problem!

Steve
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now