如何使用VBScript函数获取日志文件的最后三行内容 [英] How to obtain last three lines content of a log file using VBScript function
本文介绍了如何使用VBScript函数获取日志文件的最后三行内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以建议我使用 VBscript函数来获取文本文档的最后3行(例如: log.txt ?下面是我可以获取的代码和在我的屏幕上显示整个日志,但我想得到只有日志文件的最后3行名为log.txt。
< script type =text / Vbscript>
Option Explicit
Dim File
File =C:\\test.txt
'************************************************ ***********
Sub LoadMyFile()
myDiv.innerHTML = LoadFile(File)
End Sub
'******** ************************************************** *
函数LoadFile(File)
On Error Resume Next
Dim fso,F,ReadMe,Tab,i,paragraphe
Set fso = CreateObject(Scripting.FileSystemObject)
Set F = fso.OpenTextFile(File,1)
LoadFile = Err.Number
如果Err.Number<> 0 Then
MsgBox Err.Description,16,Error
退出功能
结束如果
ReadMe = F.ReadAll
Tab = split(ReadMe,vbcrlf)
对于i = lbound(Tab)to ubound(Tab)
paragraphe = paragraphe &安培; Tab(i)& <峰; br> 中
Next
LoadFile = paragraphe
End Function
< / script>
代码无效@ Steve
< html>
< script type =text / Vbscript>
Option Explicit
Dim File
File =C:\\test.txt
'**************** *******************************************
子LoadMyFile( )
myDiv.innerHTML = LoadFile(File)
End Sub
*************************** *********************************
功能CheckProcesses()
dim startLine
On Error Resume Next
设置F = fso.OpenTextFile(File,1 )
LoadFile = Err.Number
如果Err.Number<> 0 Then
MsgBox Err.Description,16,Error
Exit Function
End If
ReadMe = F.ReadAll
Tab = split(ReadMe,vbcrlf)
For i = lbound(Tab)to ubound(Tab)
paragraphe = paragraphe& Tab(i)& <峰; br> 中
Next
if ubound(Tab)> 2然后
startLine = ubound(Tab) - 2
else
startLine = 0
end if
For i = startLine to ubound(Tab)
paragraphe = paragraphe&标签(i)& <峰; br> 中
Next
LoadFile = paragraphe
End Function
< / script>
< input type =buttonname =Logid =Startvalue =Log Dctmonclick =CheckProcesses()>< / html>
感谢和问候
Deb
Can anyone suggest me a VBscript function to get the last 3 lines of a text document (for eg: log.txt ? Below is my code which can fetch and display the entire log on my screen but I want to get only last 3 lines of the log file named log.txt.
<script type="text/Vbscript">
Option Explicit
Dim File
File = "C:\\test.txt"
'***********************************************************
Sub LoadMyFile()
myDiv.innerHTML = LoadFile(File)
End Sub
'***********************************************************
Function LoadFile(File)
On Error Resume Next
Dim fso,F,ReadMe,Tab,i,paragraphe
Set fso = CreateObject("Scripting.FileSystemObject")
Set F = fso.OpenTextFile(File,1)
LoadFile = Err.Number
If Err.Number <> 0 Then
MsgBox Err.Description,16," Error"
Exit Function
End If
ReadMe = F.ReadAll
Tab = split(ReadMe,vbcrlf)
For i = lbound(Tab) to ubound(Tab)
paragraphe=paragraphe & Tab(i) & "<br>"
Next
LoadFile = paragraphe
End Function
</script>
Code not working@Steve
<html>
<script type="text/Vbscript">
Option Explicit
Dim File
File = "C:\\test.txt"
'***********************************************************
Sub LoadMyFile()
myDiv.innerHTML = LoadFile(File)
End Sub
************************************************************
Function CheckProcesses()
dim startLine
On Error Resume Next
Dim fso,F,ReadMe,Tab,i,paragraphe
Set fso = CreateObject("Scripting.FileSystemObject")
Set F = fso.OpenTextFile(File,1)
LoadFile = Err.Number
If Err.Number <> 0 Then
MsgBox Err.Description,16," Error"
Exit Function
End If
ReadMe = F.ReadAll
Tab = split(ReadMe,vbcrlf)
For i = lbound(Tab) to ubound(Tab)
paragraphe=paragraphe & Tab(i) & "<br>"
Next
if ubound(Tab) > 2 Then
startLine = ubound(Tab) - 2
else
startLine = 0
end if
For i = startLine to ubound(Tab)
paragraphe=paragraphe & Tab(i) & "<br>"
Next
LoadFile = paragraphe
End Function
</script>
<input type="button" name="Log" id="Start" value="Log Dctm" onclick="CheckProcesses()"></html>
Thanks and regards Deb
解决方案
Given an array of lines (Tab), the last n lines to display start from UBound(Tab) - n + 1 and end with UBound(Tab). You should test for 'less than n lines in Tab' and for 'is last line of Tab empty (trailing EOL)'.
这篇关于如何使用VBScript函数获取日志文件的最后三行内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文