This is an example of a general purpose split UDF.
Just pass the UDF the source file name, target file name and how many lines you want in each file.
If you don't pass a target file name it will use the source file name. If you don't pass a number of lines it will assume 1000 lines.
The file sequence number is placed before the file suffix of the target file, or at the end of the file if it does not have a suffix.
Code:
Break ON
$=SetOption("Explicit","ON")
$=udfSplitFile("BIGFILE.TXT","SMALLFILE.TXT",1000)
If @ERROR "ERROR: ["+@ERROR+"] "+@SERROR+@CRLF EndIf
Exit 0
Function udfSplitFile($sSource,Optional $sTarget,Optional $iMaxLines)
Dim $sSuffix
Dim $iLinesLeft,$iFileSeq
Dim $fdSource,$fdTarget
Dim $sLine
If $sTarget="" $sTarget=$sSource EndIf
If CInt($iMaxLines=0) $iMaxLines=1000 EndIf
If InStrRev($sTarget,".")
$sSuffix=SubStr($sTarget,InStrRev($sTarget,"."))
$sTarget=Left($sTarget,InStrRev($sTarget,".")-1)
EndIf
$fdSource=FreeFileHandle()
If @ERROR $udfSplitFile=@ERROR Exit @ERROR EndIf
If Open($fdSource,$sSource) $udfSplitFile=@ERROR Exit @ERROR EndIf
$sLine=ReadLine($fdSource)
While Not @ERROR
If Not($iLinesLeft)
$iLinesLeft=CInt($iMaxLines)
If $fdTarget $fdTarget=Close($fdTarget) EndIf
$fdTarget=FreeFileHandle()
If @ERROR $udfSplitFile=@ERROR Exit @ERROR EndIf
$iFileSeq=$iFileSeq+1
If Exist($sTarget+$iFileSeq+$sSuffix)
Del $sTarget+$iFileSeq+$sSuffix
If @ERROR $udfSplitFile=@ERROR Exit @ERROR EndIf
EndIf
If Open($fdTarget,$sTarget+$iFileSeq+$sSuffix,1+4) $udfSplitFile=@ERROR Exit @ERROR EndIf
EndIf
$sLine=WriteLine($fdTarget,$sLine+@CRLF)
$iLinesLeft=$iLinesLeft-1
If @ERROR $udfSplitFile=@ERROR Exit @ERROR EndIf
$sLine=ReadLine($fdSource)
Loop
If $fdTarget $fdTarget=Close($fdTarget) EndIf
$fdSource=Close($fdSource)
EndFunction