I have some text files which contain the following entries:
names=names.nsf,names1.nsf,names2.nsf
preferences=1245636456
Ports=TCPIP,LAN0,COM1,COM2
DisabledPorts=COM3,COM4,COM5
names=names.nsf
preferences=3185
Ports=TCPIP
DisabledPorts=LAN0,COM1,COM2,COM3,COM4,COM5
The first 4 entries are garbage entries, I do not want them. The last 4 are the correct one.
How do I get rid the first 4 entries, assuming each file have different entry.
Below is the sample code created but I couldn't make it work. Thank you.
.......................................................
on error resume next
Const ForReading = 1
Const ForWriting = 2
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "DisabledPorts"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\NOTESBKP\Fail\Text.txt", ForReading)
Do Until objFile.AtEndOfStream
strSearchString = objFile.ReadLine
Set colMatches = objRegEx.Execute(strSearchString)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
If strSearchString = "DisabledPorts=LAN0,COM1,COM2,COM3,COM4,COM5" Then
MsgBox "Don't do anything : " & strSearchString
Else
MsgBox "Delete this string: " & strSearchString
objFile1.Write(Replace(strSearchString, strSearchString,"DisabledPorts=LAN0,COM1,COM2,COM3,COM4,COM5"))
End If
Next
End If
Loop
names=names.nsf,names1.nsf,names2.nsf
preferences=1245636456
Ports=TCPIP,LAN0,COM1,COM2
DisabledPorts=COM3,COM4,COM5
names=names.nsf
preferences=3185
Ports=TCPIP
DisabledPorts=LAN0,COM1,COM2,COM3,COM4,COM5
The first 4 entries are garbage entries, I do not want them. The last 4 are the correct one.
How do I get rid the first 4 entries, assuming each file have different entry.
Below is the sample code created but I couldn't make it work. Thank you.
.......................................................
on error resume next
Const ForReading = 1
Const ForWriting = 2
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "DisabledPorts"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\NOTESBKP\Fail\Text.txt", ForReading)
Do Until objFile.AtEndOfStream
strSearchString = objFile.ReadLine
Set colMatches = objRegEx.Execute(strSearchString)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
If strSearchString = "DisabledPorts=LAN0,COM1,COM2,COM3,COM4,COM5" Then
MsgBox "Don't do anything : " & strSearchString
Else
MsgBox "Delete this string: " & strSearchString
objFile1.Write(Replace(strSearchString, strSearchString,"DisabledPorts=LAN0,COM1,COM2,COM3,COM4,COM5"))
End If
Next
End If
Loop