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

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-29 16:41   11   0
  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. 结果就出来了。

转载于:https://www.cnblogs.com/xuxiaoshuan/p/3651336.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP