Core Function FileOpen

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
Line 35: Line 35:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$File = FileOpen("MyFile.txt", "w")
+
$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
+
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" );
FileClose( $File )
+
FileAppend( $File, "This is line 3\n" );
EndIf
+
FileClose( $File );
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Revision as of 23:34, 16 November 2011

FileOpen( <filename>, <flag> )

Contents

Description

Opens a file for reading or writing.

Parameters

filename

Name of the text file to open.

flag

Mode (read or write) to open the file in options are:

Return Value

Success: Returns a file "handle" for use with subsequent file functions

Failure: Returns 0 if error occurs.

Remarks

N/A

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" );
	FileClose( $File );
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox