Core Function FileReadLines

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> FileReadLines( <file> ) </pre> === Description === Read all lines of text from a previously opened text file (Or specify a name of a file). === Parameters === ==== file...")
 
m (1 revision)
 
(5 intermediate revisions by one user not shown)
Line 17: Line 17:
 
Success: Returns an array of all lines
 
Success: Returns an array of all lines
  
Failure: Returns 0 if error occurs.
+
Failure: Returns null if error occurs.
  
 
=== Remarks ===
 
=== Remarks ===
Line 26: Line 26:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
For $Line In FileReadLines( "MyFile.txt" )
+
Foreach (FileReadLines( "MyFile.txt" ) as $Line)
println( "Line is: " . $Line )
+
{
Next
+
println( "Line is: " . $Line );
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 34: Line 35:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$Lines = FileReadLines( "MyFile.txt" )
+
$Lines = FileReadLines( "MyFile.txt" );
  
For $Line In $Lines
+
Foreach ($Lines as $Line)
println( "Line is: " . $Line )
+
{
Next
+
println( "Line is: " . $Line );
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 44: Line 46:
  
 
<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"))
For $Line In FileReadLines($File)
+
{
println( "Line is: " . $Line )
+
Foreach (FileReadLines($File) as $Line)
Next
+
{
FileClose( $File )
+
println( "Line is: " . $Line );
EndIf
+
}
 +
FileClose( $File );
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 12:38, 14 June 2015

FileReadLines( <file> )

Contents

Description

Read all lines of text from a previously opened text file (Or specify a name of a file).

Parameters

file

A variable containing the File handle OR a name of a file to open.

Return Value

Success: Returns an array of all lines

Failure: Returns null if error occurs.

Remarks

Trailing newlines "\n" and "\r" will be removed from the end of the returned lines automatically.

Example

Foreach (FileReadLines( "MyFile.txt" ) as $Line)
{
	println( "Line is: " . $Line );
}

Another :

$Lines = FileReadLines( "MyFile.txt" );
 
Foreach ($Lines as $Line)
{
	println( "Line is: " . $Line );
}

Heres it in use with a File Handle :

$File = FileOpen("MyFile.txt", "r");
If(isVarObj($File, "file"))
{
	Foreach (FileReadLines($File) as $Line)
	{
		println( "Line is: " . $Line );
	}
	FileClose( $File );
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox