Func _FileWriteToLine($sFile, $iLine, $sText, $fOverWrite = 0)
If $iLine <= 0 Then Return SetError(4, 0, 0)
If Not IsString($sText) Then
$sText = String($sText)
If $sText = "" Then Return SetError(6, 0, 0)
EndIf
If $fOverWrite <> 0 And $fOverWrite <> 1 Then Return SetError(5, 0, 0)
If Not FileExists($sFile) Then Return SetError(2, 0, 0)
Local $sRead_File = FileRead($sFile)
Local $aSplit_File = StringSplit(StringStripCR($sRead_File), @LF)
If UBound($aSplit_File) < $iLine Then Return SetError(1, 0, 0)
Local $hFile = FileOpen($sFile, $FO_OVERWRITE)
If $hFile = -1 Then Return SetError(3, 0, 0)
$sRead_File = ""
For $i = 1 To $aSplit_File[0]
If $i = $iLine Then
If $fOverWrite = 1 Then
If $sText <> '' Then $sRead_File &= $sText & @CRLF
Else
$sRead_File &= $sText & @CRLF & $aSplit_File[$i] & @CRLF
EndIf
ElseIf $i < $aSplit_File[0] Then
$sRead_File &= $aSplit_File[$i] & @CRLF
ElseIf $i = $aSplit_File[0] Then
$sRead_File &= $aSplit_File[$i]
EndIf
Next
FileWrite($hFile, $sRead_File)
FileClose($hFile)
Return 1
EndFunc ;==>_FileWriteToLine
将上述替换 file.au3 解决问题, 算不算是bug呢? |