Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am writing a batch script to find sum of size of files present in a directory which contains payments as a word

On executing below code:

set Size_slu = 0
for %I in (c:\Systems\SLU\*payments*.xml) do set Size_slu+=%~zI
echo total file size :%size_slu%

Above code gives me only the size of the last file although it displays size of all individual files in command prompt, How can I sum up those sizes ?

What I have tried:

set Size_slu = 0
for %I in (c:\Systems\SLU\*payments*.xml) do  set Size_slu+=%~zI
echo total file size :%size_slu%
Posted
Updated 11-Sep-18 4:07am
v2
Comments
Richard MacCutchan 11-Sep-18 7:31am    
I do not think batch scripts have a +=operator.

1 solution

As @Richard-MacCutchan has pointed out, you cannot use += in batch files you need to use the long hand version (caveat - untested)
set Size_slu = 0
set TotSize = 0

for %I in (c:\Systems\SLU\*payments*.xml) do  ( set Size_slu=%~zI
set TotSize=TotSize+Size_slu )

echo total file size :%Tot_slu%
Note the brackets as I've split this over two lines, although the following should also work
for %I in (c:\Systems\SLU\*payments*.xml) do  set Size_slu=Size_slu+%~zI
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900