帮助里找_FileWriteToLine,如果写不上可以用下面那个,这是论坛里前辈修改过的,自带的可能有点问题Func _FileWriteToLine($sFilePath, $iLine, $sText, $bOverWrite = False)
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 $bOverWrite = Default Then $bOverWrite = False
If Not (IsBool($bOverWrite) Or $bOverWrite = 0 Or $bOverWrite = 1) Then Return SetError(5, 0, 0) ; For old versions.
If Not FileExists($sFilePath) Then Return SetError(2, 0, 0)
Local $aArray = FileReadToArray($sFilePath)
Local $iUBound = UBound($aArray) - 1
If ($iUBound + 1) < $iLine Then Return SetError(1, 0, 0)
Local $hFileOpen = FileOpen($sFilePath, FileGetEncoding($sFilePath) + $FO_OVERWRITE)
If $hFileOpen = -1 Then Return SetError(3, 0, 0)
Local $sData = ""
$iLine -= 1 ; Now the array is 0-based, so reduce the line number by 1.
For $i = 0 To $iUBound
If $i = $iLine Then
If $bOverWrite Then
If $sText Then $sData &= $sText & @CRLF
Else
$sData &= $sText & @CRLF & $aArray[$i] & @CRLF
EndIf
ElseIf $i < $iUBound Then
$sData &= $aArray[$i] & @CRLF
ElseIf $i = $iUBound Then
$sData &= $aArray[$i]
EndIf
Next
FileWrite($hFileOpen, $sData)
FileClose($hFileOpen)
Return 1
EndFunc ;==>_FileWriteToLine
|