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.

Remove Line from File that Contains a string


;remove line from file
;Assumes a standard ascii text file
infile = "C:\TEMP\TEST.TXT"
outfile = "C:\TEMP\TESTOUT.TXT"
searchstr = "FindMe"
inbuf = BinaryAlloc(FileSize(infile))
outbuf = BinaryAlloc(FileSize(infile))
BinaryRead(inbuf, infile)
searchptr = BinaryIndexEx(inbuf, 0, searchstr, @fwdscan, 0) ;Ignore Case
if searchptr != -1
   ;Look for end of line
	eol = BinaryIndexEx(inbuf, searchptr, @lf, @fwdscan, 0)
	eolplusone = eol+1
	;Look for beginning of line
	bol = BinaryIndexEx(inbuf, searchptr, @lf, @backscan, 0)
	bolplusone = bol+1
	if bol != -1 
	   ;This is not the first line of the file
		;copy everything up to the previous @LF to the output buffer
		BinaryCopy(outbuf, 0, inbuf, 0, bolplusone)
	endif
	outeod = BinaryEODGet(outbuf)
	if eol != -1 ;This is not the last line of the file
		;copy everything after the @LF to the output buffer
		length = BinaryEODGet(inbuf)-eolplusone 
		if length!=0 ;handle file thats last line contains @lf
		   BinaryCopy(outbuf,outeod, inbuf, eolplusone, length )
		endif
	endif	
	BinaryWrite(outbuf, outfile)
else
	Message(searchstr,"Not found in this file")
endif
BinaryFree(inbuf)
BinaryFree(outbuf) 

Article ID:   W15892
File Created: 2004:03:30:15:41:30
Last Updated: 2004:03:30:15:41:30