Core Function FileAppend
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> FileAppend( <file>, <expression> ) </pre> === Description === Append a line of text to the end of a previously opened text file. === Parameters === ==== file ==== A v...") |
(→Example) |
||
| Line 35: | Line 35: | ||
FileAppend( $File, "This is line 2\n" ) | FileAppend( $File, "This is line 2\n" ) | ||
FileAppend( $File, "This is line 3\n" ) | FileAppend( $File, "This is line 3\n" ) | ||
| − | + | FileClose( $File ) | |
| − | + | EndIf | |
| + | </syntaxhighlight> | ||
| + | |||
| + | Example of using an array with Append | ||
| + | |||
| + | <syntaxhighlight lang="sputnik"> | ||
| + | $lines = array() ; Make a blank array | ||
| + | $lines[0] = "This will be line 4\n" | ||
| + | $lines[1] = "This will be line 5\n" | ||
| + | $lines[2] = "This will be line 6\n" | ||
| + | |||
| + | $File = FileOpen("MyFile.txt", "w") | ||
| + | If isObj($File, "file") Then ; You could just use isObj($File) however adding the "file" will make sure it is indeed a file | ||
| + | FileAppend( $File, "This is line 1\n" ) | ||
| + | FileAppend( $File, "This is line 2\n" ) | ||
| + | FileAppend( $File, "This is line 3\n" ) | ||
| + | FileAppend( $File, $lines ) | ||
FileClose( $File ) | FileClose( $File ) | ||
EndIf | EndIf | ||
Revision as of 07:26, 10 November 2011
FileAppend( <file>, <expression> )
Contents |
Description
Append a line of text to the end of a previously opened text file.
Parameters
file
A variable containing the File handle.
expression
Text to write to the end of the file.
Return Value
Success: Returns 1
Failure: Returns 0 if error occurs.
Remarks
This will always write to the end of the file.
Example
$File = FileOpen("MyFile.txt", "w") If isObj($File, "file") Then ; You could just use isObj($File) however adding the "file" will make sure it is indeed a file FileAppend( $File, "This is line 1\n" ) FileAppend( $File, "This is line 2\n" ) FileAppend( $File, "This is line 3\n" ) FileClose( $File ) EndIf
Example of using an array with Append
$lines = array() ; Make a blank array $lines[0] = "This will be line 4\n" $lines[1] = "This will be line 5\n" $lines[2] = "This will be line 6\n" $File = FileOpen("MyFile.txt", "w") If isObj($File, "file") Then ; You could just use isObj($File) however adding the "file" will make sure it is indeed a file FileAppend( $File, "This is line 1\n" ) FileAppend( $File, "This is line 2\n" ) FileAppend( $File, "This is line 3\n" ) FileAppend( $File, $lines ) FileClose( $File ) EndIf