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

File And Folder Extender

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

Search for Text in a File

 Keywords:  File Search Folder Finder Extender fafOpen fafFind Binary BinaryAlloc BinaryIndexEx 

Development of the File Search Extender (WSRCH34I.DLL) is currently suspended. There has been talk about deprecating the the File Search Extender (WSRCH34I.DLL) all together. It's main functionaily has been replaced by the File and Folder Finder Extender (WWFAF44I.DLL). However the File and Folder Finder does not support searching for text inside of files. You would need to add code to query each file located by the File and Folder Finder by using Binary operations.

Here is an example theat uses the File and Folder Finder Extender and Binary operation to search for text in a file.

;Load Appropriate Extender
If WinMetrics(-2) == 3 Then AddExtender("WWFAF64I.DLL") ; 64-bit
Else AddExtender("WWFAF44I.DLL") ; 32-bit

searchstring = 'Read '

; Initialize flags for readability
fsHidden = 1   ; Include hidden files
fsSystem = 2   ; Include system files
fsRecurse = 16  ; Look in sub directories

; Open a search handle
fsHandle = fafOpen(DirScript(), "*.txt", fsHidden|fsSystem|fsRecurse)

filelist = ''
While 1
   sFoundFile = fafFind(fsHandle)
   If sFoundFile == "" Then Break
   ; Search File For Text
   handle = BinaryAlloc( FileSize(sFoundFile) )
   BinaryRead( handle, sFoundFile )
   ptr = BinaryIndexEx( handle, 0, searchstring, @FWDSCAN, 1 )
   If ptr !=-1 Then filelist = ItemInsert (sFoundFile, -1, filelist, @LF)
   BinaryFree(handle)
EndWhile

If filelist == ""
   Pause ('Search result', ' No Files Found')
Else
   Pause ('Search result', filelist)
EndIf
fafClose(fsHandle)
Exit

Article ID:   W17575
Filename:   Search for Text in a File.txt
File Created: 2012:05:10:13:08:54
Last Updated: 2012:05:10:13:08:54