本帖最后由 樱花雪月 于 2015-11-28 17:05 编辑
3.3.9.21版本存在很多问题,在测试的过程中文本被清空... - -!
对文件改动了一些,麻烦坛友看看存在什么问题及是否在你的环境下正常使用Func _FileWriteToLine($sFilePath, $iLine, $sText, $iOverWrite = 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 $iOverWrite <> 0 And $iOverWrite <> 1 Then Return SetError(5, 0, 0)
If FileExists($sFilePath) = 0 Then Return SetError(2, 0, 0)
Local $sFileRead = FileRead($sFilePath)
Local $aArray = StringRegExp(@CRLF & $sFileRead & @CRLF, "([^\r\n]*)(?:\r\n|\n|\r|$)", 3)
$aArray[0] = UBound($aArray) - 2
If ($aArray[0] + 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)
$sFileRead = ""
For $i = 1 To $aArray[0]
If $i = $iLine Then
If $iOverWrite Then
If $sText <> '' Then $sFileRead &= $sText & @CRLF
Else
$sFileRead &= $sText & @CRLF & $aArray[$i] & @CRLF
EndIf
ElseIf $i < $aArray[0] Then
$sFileRead &= $aArray[$i] & @CRLF
ElseIf $i = $aArray[0] Then
$sFileRead &= $aArray[$i]
EndIf
Next
FileWrite($hFileOpen, $sFileRead)
FileClose($hFileOpen)
Return 1
EndFunc
|