在读取文件之前,我需要检查文件的大小。
我尝试使用发现的代码进行多条路由,似乎我不得不看.Size
,但似乎无法以任何方式使它工作。
这是到目前为止的工作代码(如果文件包含其内容):
<script for="battery_parse_1" language="VBScript">
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\core\outputs\vr1_output.log",1)
strBatteryParse1 = objFileToRead.ReadAll()
objFileToRead.Close
Set objFileToRead = Nothing
If InStr(strBatteryParse1, "EstimatedChargeRemaining") Then
strBatteryParse1Output = Right(strBatteryParse1, 2)
If strBatteryParse1Output < 10 Then
strBatteryParse1Output = Right(strBatteryParse1Output, 1)
1batteryresult.ClassName = "badge bg-red"
1batteryresult.InnerHTML = "<i class='fa fa-battery-empty'></i> " + strBatteryParse1Output + "%"
ElseIf strBatteryParse1Output < 25 Then
1batteryresult.ClassName = "badge bg-red"
1batteryresult.InnerHTML = "<i class='fa fa-battery-1'></i> " + strBatteryParse1Output + "%"
ElseIf strBatteryParse1Output < 50 Then
1batteryresult.ClassName = "badge bg-yellow"
1batteryresult.InnerHTML = "<i class='fa fa-battery-2'></i> " + strBatteryParse1Output + "%"
ElseIf strBatteryParse1Output < 75 Then
1batteryresult.ClassName = "badge bg-yellow"
1batteryresult.InnerHTML = "<i class='fa fa-battery-3'></i> " + strBatteryParse1Output + "%"
Else
1batteryresult.ClassName = "badge bg-green"
1batteryresult.InnerHTML = "<i class='fa fa-battery-4'></i> " + strBatteryParse1Output + "%"
End If
strBatteryParse1Output = strBatteryParse1Output + "% Remaining"
1batteryresult.Title = strBatteryParse1Output
Else
strBatteryParse1Output = "No data yet..."
1batteryresult.Title = strBatteryParse1Output
End If
Set objExec = Nothing
<script>
当远程计算机脱机时,电池百分比未记录到该文件中,该百分比将为空,这将导致字符串失败。看来我输入的任何代码检查文件大小是否为0kb都无法在HTA中使用。
我一直在尝试:
Set objFile = goFS.GetFile(examplefile)
If objFile.Size > 0 Then
但没有成功。
编辑:解决方案在Ansgar Wiechers的评论中。 Hta需要使用
Set objFile = CreateObject("Scripting.FileSystemObject").GetFile
代替
Set objFile = goFS.GetFile(examplefile)