vbscript - How to read a text file to numbers and then get the total value of those numbers -


i'm working on script find out how free storage there is. script checks database find out store names queries these using cmd. outputs file remaining storage. cannot seem find way combine these values , bring total amount.

script:

dim objfilesys set objfilesys = createobject("scripting.filesystemobject") if objfilesys.fileexists("a.txt")     objfilesys.deletefile "a.txt"     wscript.echo ("old file found , deleted")     else     wscript.echo ("old file not found, script continue") end if  wscript.sleep 500  set objconnection = createobject("adodb.connection") set objrecordset = createobject("adodb.recordset") set oshell = wscript.createobject ("wscript.shell") dim strres dim strdc dim strspc  objconnection.open _     "provider=sqloledb;data source=dls-bsp-sdb;" & _     "initial catalog=dom_site;" & _     "user id=*****;password=*****" objrecordset.open "****", objconnection  while not objrecordset.eof     wscript.sleep 1000    strres = objrecordset.fields("volume").value    strdc = ("cmd /c dir /-c " &strres)+"| find /i ""bytes free"""    wscript.echo strres    oshell.run "" & strdc + " >> a.txt"    'wscript.echo strspc    objrecordset.movenext loop  objrecordset.close  wscript.sleep 1000  const forreading = 1 const forwriting = 2  set objfso = createobject("scripting.filesystemobject") set objfile = objfso.opentextfile("a.txt", forreading)  strtext = objfile.readall objfile.close strnewtext = replace(strtext, "               5 dir(s)  ", "") strnewtext1 = replace(strnewtext, " bytes free", "") strnewtext2 = replace(strnewtext1, " ", "")  set objfile = objfso.opentextfile("a.txt", forwriting) objfile.writeline strnewtext2   objfile.close  wscript.sleep 1000  set objfiletoread = createobject("scripting.filesystemobject").opentextfile("a.txt",1) dim strline  while not objfiletoread.atendofstream      strline = objfiletoread.readline()      wscript.echo strline loop wscript.echo strline objfiletoread.close 

this outputs text file containing like

15363938635776 4314728202240 4250596589568 15386325426176 9204097486848 15406486990848

i know can read file using vbscript like

const forreading = 1  set objfso = createobject("scripting.filesystemobject") set objfile = objfso.opentextfile("a.txt", forreading)  until objfile.atendofstream     strline = objfile.readline     wscript.echo strline loop  objfile.close 

i need total instead of viewing text.

you can use accumulator variable

mysum = 0 

and add loop

do until objfile.atendofstream     strline = objfile.readline     mysum = mysum + clng(strline) loop 

mysum contains total.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -