del2.vbs

来自「VBS 运行 调用 腾讯验证码 通过maxthon 可 实现自动调用」· VBS 代码 · 共 61 行

VBS
61 行
字号
Option Explicit

Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2

Dim sTextToLookFor, iLinesToSkip, iLinesToSkipLeft, oFSO, sFile, fFile
Dim bRewriteNeeded, sLine, aFileContent, iArrCount, sFileContent


' file to check/update
sFile = "\\Server-u\QQnetbar$\lz.htm"

' note that LCase statements further below in the code
' makes the match not case sensitive
sTextToLookFor = "    <td class="

' how many additional lines to skip if text found
iLinesToSkip =23 '搜索内容下要删除的行


Set oFSO = CreateObject("Scripting.FileSystemObject")

Set fFile = oFSO.OpenTextFile(sFile, ForReading, _
FailIfNotExist, OpenAsASCII)

bRewriteNeeded = False ' init value
iLinesToSkipLeft = 0  '从头行开始要删除的行数

' build an array of all lines not staring with text defined in sTextToLookFor
aFileContent = Array()
Do Until fFile.AtEndOfStream
sLine = fFile.ReadLine
If Left(LCase(sLine), Len(sTextToLookFor)) = LCase(sTextToLookFor) Then
' set the rewrite marker true
bRewriteNeeded = True
' reset skip lines counter
iLinesToSkipLeft = iLinesToSkip

Elseif iLinesToSkipLeft > 0 Then
iLinesToSkipLeft = iLinesToSkipLeft - 1

Else
iArrCount = UBound(aFileContent) + 1
ReDim Preserve aFileContent(iArrCount)
aFileContent(iArrCount) = sLine
End If
Loop

fFile.Close

' only update file if necessary
If bRewriteNeeded Then
' Join the array and add a trailing line feed
sFileContent = Join(aFileContent, vbCrLf) & vbCrLf
Set fFile = oFSO.OpenTextFile(sFile, ForWriting, True)
fFile.Write sFileContent
fFile.Close
End If

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?