WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Binary Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Remove a Line from a File using Binary Functions

Keywords: 	 remove a line binary

Question:

Due to some extensive problems with our proxy server, I need to remove a line from the company's prefs.js file for Netscape. This si what I have built so far, and it being a Monday, can't seem to figure out how to re-write the file without the offending line. Perhaps a little Martinesque light could be shed? (uh-oh, being reading too many Gary Whatcott posts again.. ;o) )
BoxOpen("Netscape Update","Searching")
AddExtender("wsrch34I.dll")
file="prefs.js"
hand=srchInit("C:\",file,"","",16)
while 1 
    a=srchNext(hand) 
    if a=="" then break 
    Buffer=BinaryAlloc(50000); more than enough for 7k file
    Line=BinaryIndexNc(Buffer,0,'user_pref("network.proxy.type", 1)',@FWDSCAN)
    ; gotta remove that line!!! and re-write the file...
    ; I hate mondays, my brain is not working today... 
endwhile
srchFree(hand) 
exit

Answer:

UNDEBUGGED !!
Buffer=BinaryAlloc(50000); more than enough for 7k file
outbuf=BinaryAlloc(50000)
userpref=BinaryIndexNc(Buffer,0,'user_pref("network.proxy.type", 1)',@FWDSCAN)

BinaryCopy(outbuf,0,Buffer,0,userpref)
cuthere=BinaryIndexNC(Buffer,userpref,@CRLF,@FWDSCAN)+2

a=BinaryEODGet(outbuf)
b=BinaryEODGet(Buffer)
BinaryCopy(outbuf,a,Buffer,cuthere,b-cuthere)

BinaryWrite(outbuf,"TEST.XXX")
BinaryFree(outbuf)
BinaryFree(buffer)

Article ID:   W12733
Filename:   Remove Line from File.txt
File Created: 2001:03:01:15:00:58
Last Updated: 2001:03:01:15:00:58