Core Function FileRead

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> FileRead( <file>, <expression> ) </pre> === Description === Read a number of characters from a previously opened text file starting from current File Steam pointer locati...")
 
(Description)
 
(6 intermediate revisions by one user not shown)
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
  
Read a number of characters from a previously opened text file starting from current File Steam pointer location.
+
Read a number of bytes from a previously opened text file starting from current File Steam pointer location and return them as a string.
  
 
=== Parameters ===
 
=== Parameters ===
Line 15: Line 15:
 
==== expression  ====
 
==== expression  ====
  
Optional; Number of letters to read.
+
Optional; Number of bytes to read.
  
 
If this param is not provided it will read to the end of the file.
 
If this param is not provided it will read to the end of the file.
Line 23: Line 23:
 
Success: Returns a string
 
Success: Returns a string
  
Failure: Returns 0 if error occurs.
+
Failure: Returns null if error occurs.
  
 
=== Remarks ===
 
=== Remarks ===
Line 32: Line 32:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$File = FileOpen("MyFile.txt", "r")
+
$File = FileOpen("MyFile.txt", "r");
If isObj($File, "file") Then
+
If(isVarObj($File, "file"))
$Str = FileRead($File)
+
{
println( "String is: " . $Str )
+
$Str = FileRead($File);
FileClose( $File )
+
println( "String is: " . $Str );
EndIf
+
FileClose( $File );
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 43: Line 44:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$File = FileOpen("MyFile.txt", "r")
+
$File = FileOpen("MyFile.txt", "r");
If isObj($File, "file") Then
+
If(isVarObj($File, "file"))
FileSeek($File, 7, "b")
+
{
$Str = FileRead($File)
+
FileSeek($File, 7, "b");
println( "String is: " . $Str )
+
$Str = FileRead($File);
FileClose( $File )
+
println( "String is: " . $Str );
EndIf
+
FileClose( $File );
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 07:21, 18 June 2015

FileRead( <file>, <expression> )

Contents

Description

Read a number of bytes from a previously opened text file starting from current File Steam pointer location and return them as a string.

Parameters

file

A variable containing the File handle.

expression

Optional; Number of bytes to read.

If this param is not provided it will read to the end of the file.

Return Value

Success: Returns a string

Failure: Returns null if error occurs.

Remarks

N/A

Example

$File = FileOpen("MyFile.txt", "r");
If(isVarObj($File, "file"))
{
	$Str = FileRead($File);
	println( "String is: " . $Str );
	FileClose( $File );
}

You could also tell it where to begin from example :

$File = FileOpen("MyFile.txt", "r");
If(isVarObj($File, "file"))
{
	FileSeek($File, 7, "b");
	$Str = FileRead($File);
	println( "String is: " . $Str );
	FileClose( $File );
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox