Actually, I'm doing this all in text mode, with the parameters from the command line. I'll post a generic version of the code, after it's finished.
But right now, it's working fine, and is generating the expected file.
Moderator: Rathinagiri
Code: Select all
#include "minigui.ch"
#include "hmg.ch"
#include "FILEIO.CH"
Function Extract_Lines_from_LargeTextFiles( Source_FileName_s, Target_FileName_s, Number_of_Lines_to_Extract_s )
Local Number_of_Lines_to_Extract_n := 0
Local First_Needed_Record_n := 0
Local Line_s := ""
Local Row_Number_n := 0
Local Current_Recno_n := 0
Local Total_Number_Of_Records_n := 0
Local Eof_b := .F.
Local Error_o
If Source_FileName_s == Nil .OR. Target_FileName_s == Nil
? "Syntax is"
? "Extract_Lines_from_LargeTextFiles (Source FileName) (Target FileName) (Optional: Number of lines to extract from the end of the file)"
Close all
Return
EndIf
DEFAULT Number_of_Lines_to_Extract_s TO "1000"
Number_of_Lines_to_Extract_n := Val( Number_of_Lines_to_Extract_s )
TRY
HB_Fuse(Source_FileName_s)
Current_Recno_n := hb_FRecNo()
Total_Number_Of_Records_n := HB_FlastRec()
If Total_Number_Of_Records_n > Number_of_Lines_to_Extract_n
First_Needed_Record_n := Total_Number_Of_Records_n - Number_of_Lines_to_Extract_n
HB_FGoto(First_Needed_Record_n)
else
HB_FGoTop()
EndIf
Current_Recno_n := hb_FRecNo()
SET CONSOLE OFF
SET PRINTER ON
SET PRINTER TO (Target_FileName_s)
DO WHILE ! hb_FAtEof()
Line_s := HB_FReadLN()
HB_FSkip()
? Line_s
Loop
ENDDO
SET PRINTER OFF
SET PRINTER TO
SET CONSOLE ON
HB_FGoBottom()
HB_FUse()
CATCH Error_o
? "Error: ", Error_o:Description
Close all
Return
END
Return Nil