Searching all text files in a directory

tsteward

Active Member
Licensed User
Any ideas how I might quickly search all text files (with the extension 'txt') in a single folder for given text?
 

Cableguy

Expert
Licensed User
List all files is easy, searching for a particular string in any of those files...
The easiest way is to load esch file and do the search in each of them, populating some sort of "Hit-list" with the results...
But that would be very time and resouce consuming..
 

tsteward

Active Member
Licensed User
List all files is easy, searching for a particular string in any of those files...
The easiest way is to load esch file and do the search in each of them, populating some sort of "Hit-list" with the results...
But that would be very time and resouce consuming..
Yeah well that is what I have done so far.
I guess I was hoping someone had some other method.

My Code(obviously I will replace the message box with populating a list)
B4X:
ALFiles.Clear
  FileSearch(ALFiles,SubString(wikiDir,0,StrLength(wikiDir)-1),"*.txt")
  For f=0 To ALFiles.Count-1
   FileOpen (c1, ALFiles.Item(f), cRead ,, cASCII)
   contents = FileReadToEnd(c1)
   FileClose (c1)
   r=StrIndexOf(contents,"[" & currentpage & "]",0) '+ StrIndexOf(contents,"][" & currentpage & "]]",0)
   s = StrIndexOf(contents, "][" & currentpage & "]",0)
   If r>-1 AND s = -1 Then
    Msgbox(ALFiles.Item(f) & crlf & "Is Backlink")
   End If
  Next
 

tsteward

Active Member
Licensed User
Search Subdirectories

How can I get all the *.txt files in the current directory and ALL sub directories. Not sure how to find and keep track of all the sub dirs
 

klaus

Expert
Licensed User
Here you have an example, it goes only 3 levels of subdirectories deep, if you need more you can add the needed code.

Best regards.
 

Attachments

Top