# Solved: Parsing a multi-line command output



## scrfix (May 3, 2009)

Hello,

*Issue*: Comparing file sizes of two of the same files on two different computers.

*Notes*: I know that the FOR statement using %~zI and the DIR /B will provide me the file size but I have been unsuccessful in attaining the actual size utilizing those commands. The FOR statement is simply my lack of knowledge on how to properly utilize that. The DIR /B, I have researched how to parse multi-line outputs from within a batch and cannot find anything that pertains to what I am trying to do.

*Goal*:

Compare Two File Sizes
Make Backup Copy of Files
Copy Greater File size over to other spot

I have attempted the following ways and lots more:

```
:: Failed: FOR /F "usebackq delims==" %%~zI IN (`DIR %_file%`) DO @echo %%~zI
:: Only returns Bytes Free: For /F "Tokens=2* skip=2" %%a In ('DIR %_file%') Do set _pc1file=%%b
:: Only returns 0: For /F %%a In ('DIR %_file%') Do set _pc1file=%%a
```
When you do a directory search for the specified file the following is what you get. I am attempting to capture the *7,271,880* but can only capture the last line.

C:\Users\Username>dir EPOSTAGE.DBF
Volume in drive C has no label.
Volume Serial Number is 88CB-496A

Directory of C:\Users\Username

05/25/2011 05:02 PM 7,271,880 EPOSTAGE.DBF
1 File(s) 7,271,880 bytes
0 Dir(s) 30,788,046,848 bytes free

*Question*: 
How would I capture only the 7,271,880?

Thanks,


----------



## Squashman (Apr 4, 2003)

Thought we have given you enough examples over the past couple of years on For Loops.

Remember that in a batch file you need double %%. Command line only needs one %.

```
H:\>FOR /F "tokens=*" %I IN ('dir /a-d /b NES*') DO echo %~zI

H:\>echo 25600
25600

H:\>echo 26112
26112

H:\>echo 112320
112320

H:\>echo 84780
84780

H:\>echo 5077
5077

H:\>echo 5077
5077

H:\>echo 23552
23552

H:\>echo 4790
4790

H:\>echo 26112
26112

H:\>echo 95985
95985

H:\>echo 16384
16384

H:\>echo 19968
19968
```


----------



## scrfix (May 3, 2009)

Nevermind, I had a space after _filesize = %% and it needed to be _filesize=%%.
It has been changed below.

Thank you for your assistance.

Yes you guys have provided me with examples over the past years, I looked through those FOR loops too trying to figure this one out.

The echo works great but when I attempt to set it to a value it shows Echo is off. When I turn echo on:


```
@echo on
set _file=EPOSTAGE.DBF
FOR /F %%I IN ('dir /a-d /b %_file%') DO SET _filesize=%%~zI
set _file=
echo %_filesize%
```
*Outputs*
C:\Users\Username>FOR /F "tokens=*" %I IN ('dir /a-d /b EPOSTAGE.DBF') DO SET _filesize = %~zI
C:\Users\Username>SET _filesize = 7271880
C:\Users\Username>set _file=
C:\Users\Username>echo
ECHO is on.

I am attempting to capture just the 7271880. It appears to set it properly but then loses it after the FOR statement? That is the part that I am not getting. I shouldn't need delayedExpansion for this should I?


----------



## Squashman (Apr 4, 2003)

not sure why you are using TOKENS=1 and EOL=0. You don't need them.


----------



## scrfix (May 3, 2009)

That was just for testing. I took them out in the final version but apparently did not take them out there.


----------

