Core Function FileAppendBinary

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> FileAppendBinary( <file>, <binary-array> ) </pre> === Description === Append the data from a binary variable to the end of a previously opened file. === Parameters === ...")
 
(Example)
Line 30: Line 30:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$binary1 = Pack("z0", "Hello World!\n")
+
$binary1 = Pack("z0", "Hello World!\n");
$binary2 = Pack("z0", "Hi there\n")
+
$binary2 = Pack("z0", "Hi there\n");
$binary3 = Pack("z0", "This will be line 3\n")
+
$binary3 = Pack("z0", "This will be line 3\n");
  
$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 ( isVarObj($File, "file") )
FileAppendBinary( $File, $binary1 )
+
{
FileAppendBinary( $File, $binary2 )
+
FileAppendBinary( $File, $binary1 );
FileAppendBinary( $File, $binary3 )
+
FileAppendBinary( $File, $binary2 );
FileClose( $File )
+
FileAppendBinary( $File, $binary3 );
EndIf
+
FileClose( $File );
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Revision as of 01:42, 19 November 2011

FileAppendBinary( <file>, <binary-array> )

Contents

Description

Append the data from a binary variable to the end of a previously opened file.

Parameters

file

A variable containing the File handle.

binary-array

The binary variable with bytes 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

$binary1 = Pack("z0", "Hello World!\n");
$binary2 = Pack("z0", "Hi there\n");
$binary3 = Pack("z0", "This will be line 3\n");
 
$File = FileOpen("MyFile.txt", "w");
If ( isVarObj($File, "file") )
{
	FileAppendBinary( $File, $binary1 );
	FileAppendBinary( $File, $binary2 );
	FileAppendBinary( $File, $binary3 );
	FileClose( $File );
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox