Core Function FileWrite
From Sputnik Wiki
(Difference between revisions)
(→Example) |
(→Example) |
||
Line 32: | Line 32: | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | $File = FileOpen("MyFile.txt", "w") | + | $File = FileOpen("MyFile.txt", "w"); |
− | If isObj($File, "file") | + | If(isObj($File, "file")) // 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 1\n" ); |
− | FileAppend( $File, "This is line 3\n" ) | + | FileAppend( $File, "This is line 2\n" ); |
− | FileSeek( $File, 0, "B" ) | + | FileAppend( $File, "This is line 3\n" ); |
− | FileWrite( $File, "Replace Line 1" ) | + | FileSeek( $File, 0, "B" ); |
− | FileClose( $File ) | + | FileWrite( $File, "Replace Line 1" ); |
− | + | FileClose( $File ); | |
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Revision as of 00:24, 17 November 2011
FileWrite( <file>, <expression> )
Contents |
Description
Write text to previously opened text file at the current File Steam pointer location.
Parameters
file
A variable containing the File handle.
expression
Text to write to file.
Return Value
Success: Returns 1
Failure: Returns 0 if error occurs.
Remarks
You can set the File Steam pointer location with FileSeek( <file>, <offset>, <flag> ).
Warning this will not write to the end of the file unless you tell it to with seek so if you want to write to end of the file you should use FileAppend( <file>, <expression> ) instead.
Example
$File = FileOpen("MyFile.txt", "w"); If(isObj($File, "file")) // 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" ); FileSeek( $File, 0, "B" ); FileWrite( $File, "Replace Line 1" ); FileClose( $File ); }