How to use VBS code to find a certain string in a text file and write it to another file? (Output the lines containing the string)
[ Last edited by s11ss on 2007-12-14 at 04:24 PM ]
[ Last edited by s11ss on 2007-12-14 at 04:24 PM ]
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
| Rater | Score | Time |
|---|---|---|
| s11ss | +4 | 2007-12-12 21:06 |
Originally posted by s11ss at 2007-12-12 21:10:
Does brother vkill know if there is a screen-clearing command similar to cls when executing vbs with cscript?

<html>
<title>cls</title>
<HTA:APPLICATION
ID="MyhyliApp"
APPLICATIONNAME="cls"
BORDER="thin"
BORDERSTYLE="normal"
VERSION="1.0"
SCROLL="no"
INNERBORDER="yes"
CONTEXTMENU="yes"
CAPTION="yes"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
NAVIGABLE="yes"
/>
<script language="VBScript">
windowswidth = 640
windowsheight = 480
window.resizeTo windowswidth, windowsheight
ileft=(window.screen.width-windowswidth)/2
itop=(window.screen.height-windowsheight)/2
window.moveTo ileft,itop
</script>
<body bgcolor=#e0e0e0>
<table align="center">
<tr>
<td align="center">Clear and then refresh with F5</td>
</tr>
<tr>
<td id="Menu" align="center"></td>
</tr>
</table>
<table width="100%" style="position:absolute; bottom:20px;"><td>
<table align="center" style="font:bold 15px 宋体;">
<tr align="center">
<td><button onclick="CLS1" style="width:100;">Clear Content</button></td>
</tr>
<tr align="center">
<td><button onclick="CLS2" style="width:100;">Hide Content</button></td>
</tr>
</table>
</td></table>
</body>
<script language="VBScript">
Menu.innerHTML = "Test<br>Test<br>Test<br>Test<br>Test<br>"
Sub CLS1
Menu.innerHTML = ""
End Sub
Sub CLS2
Menu.style.display = "none"
End Sub
</script>
<html>
file=Wscript.ScriptFullName
'file=WScript.Arguments(0)
Dim str
set str = CreateObject("Adodb.Stream")
str.Type = 1
str.Mode = 3
str.Open
str.Loadfromfile file
Bin=str.read(6)
Usage = MidB(Bin,6,1)
str.Close
set str = Nothing
WScript.echo "The character at the 6th byte of this script is “",Usage,"”"
set fso=createobject("scripting.filesystemobject")
If fso.FileExists("text.txt")=0 then 'Check if the text.txt file exists
fso.createtextfile("text.txt")
end if
set file=fso.opentextfile("text.txt",8) 'Open the file in append mode
set opfile=fso.opentextfile("a.txt") 'Open the file
do while opfile.atendofstream=false
line=opfile.readline 'Read a line of content
if instr(line,"Search character")>0 then 'Judge if it contains the search character
str=str&line&vbcrlf 'Add to buffer
end if
loop
file.writeline (str) 'Write the line with the search character to the text.txt file
Originally posted by zh159 at 2007-12-14 16:42:
Set fso = CreateObject("Scripting.FileSystemObject")
source = "a.txt"
strFind = "b"
Set f = fso.OpenTextFile(source,1)
While not f.AtEndOfStream
strRe ...