Thanks to this forum I was able to create the following code:
Code: Select all
File.s="C:\Temp\FileToSearch.txt"
NewList Words.s()
AddElement(Words())
Words()="TextToFind"
RF=ReadFile(#PB_Any,File,#PB_File_SharedRead)
While Not Eof(RF)
FileText$=ReadString(RF,#PB_File_IgnoreEOL)
Wend
CloseFile(RF)
ForEach Words()
If FindString(FileText$,Words())>0
Debug "Word found : " + Words()
EndIf
Next
Code: Select all
File.s="C:\Temp\FileToSearch.txt"
NewList Words.s()
AddElement(Words())
Words()="TextToFind"
RF=ReadFile(#PB_Any,File,#PB_File_SharedRead)
Lengte=Lof(RF)
*MemoryID=AllocateMemory(Lengte)
If *MemoryID
If ReadData(RF,*MemoryID,Lengte)=Lengte
FileText$=PeekS(*MemoryID,Lengte,#PB_UTF8)
EndIf
CloseFile(RF)
ForEach Words()
If FindString(FileText$,Words())>0
Debug "Word found : " + Words()
EndIf
Next
EndIf
Also, this seems to work with large files (500Mb+), but when I use it on a file exceeding 1.3Gb, the PeekS returns an empty string. Can anyone help me out what to do? Or is it not possible to read the file in one string despithe the comment that a String is unlimited?
-Code edited as a result of feedback from mk-soft-
Many thanks in advance,
Geert