Core Function FileSeek

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> FileSeek( <file>, <offset>, <flag> ) </pre> === Description === Changes the current File Stream location on a previously opened text file. === Parameters === ==== file ...")
 
(Example)
Line 38: Line 38:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
 +
$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
 +
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 )
 +
EndIf
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Revision as of 09:50, 9 November 2011

FileSeek( <file>, <offset>, <flag> )

Contents

Description

Changes the current File Stream location on a previously opened text file.

Parameters

file

A variable containing the File handle.

offset

Any valid numeric expression above zero.

flag

The position to START from (Then you can add your offset) is set here with these flags:

Return Value

Success: Returns 1

Failure: Returns 0 if error occurs.

Remarks

N/A

Example

$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
	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 )
EndIf
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox