小技巧:统计文本文件行数

  1. 第三种方法更简便:首先也是新建一个TXT文件,然后将下面代码复制进去。

    <job id="HowManyLines">

    <script language="VBScript">

    Const ForReading = 1

    Dim strMsg, fileNames, objFile, lineCount(100)

    set objFSO = CreateObject("Scripting.FileSystemObject")

    set WshShell = WScript.CreateObject("WScript.Shell")

    strMsg = InputBox("Please enter your file name:")

    fileNames = Split(strMsg, " ", -1, 1)

    For i = 0 To UBound(fileNames)

    Set objFile = objFSO.OpenTextFile(fileNames(i) & ".txt", ForReading)

    Do While objFile.AtEndOfStream <> True

    objFile.ReadLine

    lineCount(i) =lineCount(i) + 1

    Loop

    objFile.Close

    Next

    strMsg = ""

    For i = 0 To UBound(fileNames)

    strMsg = strMsg & lineCount(i)& " "

    Next

    MsgBox(strMsg)

    </script>

    </job>

  2. 保存,并和上面两种方法一样,将这个新建的TXT文本的后序格式名改为wsf

  3. 双击打开,输入你要查找的TXT文本名字

  4. 结果就出来了。

posted @ 2014-04-08 10:00  程序员徐坤  阅读(921)  评论(0编辑  收藏  举报