Function to count number of lines in a text file

后端 未结 7 708
栀梦
栀梦 2020-12-29 08:04

Need a function that will accept a filename as parameter and then return the number of lines in that file.

Should be take under 30 seconds to get the count of a 10 m

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-29 08:33

    You could try some variation on this

    cnt = 0
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set theFile = fso.OpenTextFile(filespec, ForReading, False)
    Do While theFile.AtEndOfStream <> True
       theFile.SkipLine
       c = c + 1
    Loop
    theFile.Close
    WScript.Echo c,"lines"
    

提交回复
热议问题