如何统计TXT记事本文本的行数
1、第一种方法拒墨是:新建一个TXT文本,将下面的代码复制进去:
<job id="HowManyLines">
<script language="VBScript">
Const ForReading = 1
Dim objFSO, fold, f, strMsg, fileNames(100), objFile, lineCount(100),files,i
set objFSO = CreateObject("Scripting.FileSystemObject")
set fold = objFSO.GetFolder("E:\统计行数\")
set files = fold.Files
For Each f in files
If objFSO.GetExtensionName(f) = "txt" Then
Set objFile = objFSO.OpenTextFile(f, ForReading)
Do While objFile.AtEndOfStream <> True
objFile.ReadLine
lineCount(i) = lineCount(i) + 1
Loop
objFile.Close
fileNames(i) = f.Name
i = i + 1
End If
Next
strMsg = ""
For i = 0 To UBound(fileNames)
If fileNames(i)<>"" Then
strMsg = strMsg & fileNames(i) & ":" & lineCount(i)
strMsg = strMsg & Chr(13)
End If
Next
MsgBox(strMsg) 匠速
</script>
</job>
然后保存,并将TXT文本的后序格式名改为:wsf 如图

2、然后将上面 E:\统计行数\ 改为你自己想要的目录

3、将你要将统计的TXT文本以及刚刚生成的wsf文件放在该目录下。

4、双击打开该wsf文件,就会自动统计你设定目录下的TXT文件的行数。 如图,我有两个TXT文件,往光茄都统计出来了。

1、第二种方法是统计指定目录下面的指定TXT文本。方法如下:
先将下面代码复制进一个新建的TXT文本:
<job id="vbs">
<script language="VBScript">
Const ForReading = 1
Dim objFSO, objFile, i
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("000.txt", ForReading)
Do While objFile.AtEndOfStream <> True
objFile.ReadLine
i = i + 1
Loop
objFile.Close
Wscript.Echo i
</script>
</job>
2、将“000.txt”改成当前目录下你想要统计的TXT文件的名称,例如我自己这里要统计的就是000.txt

3、保存后,将代码的TXT文本后序格式名改成wsf。

4、将wsf文件和你要统计的TXT文本放在同一目录下,双击打开wsf文件,就可以统计你刚才指定的TXT文本的行数。

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、结果就出来了。
