Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Text search challenge...
Message
From
17/02/2003 06:19:27
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
16/02/2003 21:10:17
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00753959
Message ID:
00754042
Views:
22
>Who can offer the most efficient (i.e. fastest) code to accomplish the following?
>
>I need to search 3,000 ascii text files spread among approximately 20 sub-dirs. The files might contain 200-300 lines, bu I only need to search the first 7 lines of each file for a short keyword that the user will enter into a textbox. I report all matches into a listbox.
>
>My current method opens the file for an ascii read, then "for x= 1 to 7" and use the ATC() function to look for a match on each read line. It works, but it's kinda slow, just becuase there are so many files.
>
>I will post my code when I get to work on Monday, and you can critique it.
>
>Thanks.

Matt,
Others already offered good solutions. As an addition an almost developer only (if not a web project) solution is to use fulltext search with indexing service. ie :
qry = CreateObject("ixsso.Query")
utl = CreateObject("ixsso.Util")
utl.AddScopeToQuery(qry,sys(5)+curdir(),"deep") && Or shallow for just curdir
qry.Query = "buchanan near steven and @filename = *.txt"
qry.Catalog = 'System'
qry.SortBy = "path[a], size[d]"
qry.Columns = "path, size, write"
qry.MaxRecords = 300
oRecordset = qry.CreateRecordSet("nonsequential")
? oRecordset.RecordCount
IF oRecordset.RecordCount > 0
	lcTempXML = SYS(2015)+'.xml'
	oRecordset.Save(lcTempXML,1)
	XMLTOCURSOR(lcTempXML,'FileList',512)
        erase (lcTempXML)
	BROWSE FIELDS path, size, write, mypath = MLINE(path,1)
	return
endif	
	
*!*	IF oRecordset.RecordCount > 0
*!*	  _Screen.fontname = "Courier New"
*!*	  _Screen.fontsize = 10	
*!*	  oRecordset.MoveFirst
*!*	  Do while !oRecordSet.EOF
*!*	  	lcRecord = ''
*!*	    For Each ofield In oRecordSet.Fields
*!*	      lcRecord = lcRecord + transform(oField.Value) + CHR(9)
*!*	    Endfor
*!*	    ? lcRecord
*!*	    oRecordSet.MoveNext
*!*	  Enddo
*!*	endif
I use this primarily for myself to locate prg,sc*,vc*'s containing some keywords. Supported in w2k and later NTs.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform