;======================================== ;Function name: _FileWriteToLine ;Description: Write text to specified line in a file ;Parameters: ; $sFile - The file to write to ; $iLine - The line number to write to ; $sText - The text to write ; $fOverWrite - if set to 1 will overwrite the old line ; if set to 0 will not overwrite ;Requirement(s): None ;Return Value(s): On success - 1 ; On Failure - 0 And sets @ERROR ; @ERROR = 1 - File has less lines than $iLine ; @ERROR = 2 - File does not exist ; @ERROR = 3 - Error opening file ; @ERROR = 4 - $iLine is invalid ; @ERROR = 5 - $fOverWrite is invalid ; @ERROR = 6 - $sText is invalid ;Author(s): cdkid ;Note(s): ;========================================= Func _FileWriteToLine($sFile, $iLine, $sText, $fOverWrite = 0) If $iLine <= 0 Then SetError(4) Return 0 EndIf If Not IsString($sText) Then SetError(6) Return 0 EndIf If $fOverWrite <> 0 And $fOverWrite <> 1 Then SetError(5) Return 0 EndIf If Not FileExists($sFile) Then SetError(2) Return 0 EndIf $filtxt = FileRead($sFile, FileGetSize($sFile)) $filtxt = StringSplit($filtxt, @CRLF, 1) If UBound($filtxt, 1) < $iLine Then SetError(1) Return 0 EndIf $fil = FileOpen($sFile, 2) If $fil = -1 Then SetError(3) Return 0 EndIf For $i = 1 To UBound($filtxt) - 1 If $i = $iLine Then if $fOverWrite = 1 then if $sText <> '' Then FileWrite($fil, $sText & @CRLF) Else filewrite($fil, $sText) EndIf EndIf If $fOverWrite = 0 Then FileWrite($fil, $filtxt[$i] & @CRLF) EndIf ElseIf $i < UBound($filtxt, 1) - 1 Then FileWrite($fil, $filtxt[$i] & @CRLF) ElseIf $i = UBound($filtxt, 1) - 1 Then FileWrite($fil, $filtxt[$i]) EndIf Next FileClose($fil) Return 1 EndFunc;==>_FileWriteToLine
~cdkid
EDIT
updated it so i THINK it works with all the things MHz mentioned... tell me if i'm wrong
/EDIT
EDIT2
updated again, and have sent it in for the UDF library
/EDIT2
EDIT3
updated it with the version that has been sent in for the UDF library
/EDIT3
EDIT4
updated so if $sText is "" and $fOverWrite is 1 deletes line rather than replacing it with ""
/EDIT4
Edited by cdkid, 21 February 2006 - 08:13 PM.







