WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get Line Count and Append if Necessary

 Keywords: Line Count  

Question:

I'm new to Winbatch and wanted to know how to do the following. I need to open a file and count the number of lines. If the count is not divisible by 10 I need to add lines containing 95 nines. If the line count is say 104 - I'll need to add six lines containing 95 nines.

Answer:

; Create testfile.
; Note: File will be overwritten!
strFilename = ".\test.txt"
FilePut (strFilename, StrFill (@CRLF, 24))  ;12 lines.

intFileGetLineCount = FileSize (strFilename) - StrLen (StrReplace (FileGet (strFilename), @LF, ""))
intAdd = intFileGetLineCount mod 10
If intAdd
   strStream = FileGet (strFilename)
   For intI = 10 To intAdd By -1
      strStream = strStream : StrFill (9, 95) : @CRLF
   Next
   FilePut (strFilename, strStream)
EndIf
Run (strFilename, "")
Exit


Article ID:   W17928
Filename:   Get line Count and Append if Necessary.txt
File Created: 2009:08:06:10:47:32
Last Updated: 2009:08:06:10:47:32