Core Function FileSeek
From Sputnik Wiki
(Difference between revisions)
(→Example) |
m (1 revision) |
||
(6 intermediate revisions by one user not shown) | |||
Line 19: | Line 19: | ||
==== flag ==== | ==== flag ==== | ||
− | The position to START from (Then you can add your offset) is set here with these flags: | + | Optional; The position to START from (Then you can add your offset) is set here with these flags: |
− | * "b" = Base location is Beginning of the file | + | * "b" = Base location is Beginning of the file (Default) |
* "e" = Base location is End of the file | * "e" = Base location is End of the file | ||
* "c" = Base location is the current location | * "c" = Base location is the current location | ||
Line 38: | Line 38: | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | $File = FileOpen("MyFile.txt", "w") | + | $File = FileOpen("MyFile.txt", "w"); |
− | If | + | If(isVarObj($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" ); |
− | FileSeek( $File, 0 | + | FileAppend( $File, "This is line 3\n" ); |
− | FileWrite( $File, "Replace Line 1" ) | + | FileSeek( $File, 0 ); |
− | FileClose( $File ) | + | FileWrite( $File, "Replace Line 1" ); |
− | + | FileClose( $File ); | |
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:38, 14 June 2015
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
Optional; The position to START from (Then you can add your offset) is set here with these flags:
- "b" = Base location is Beginning of the file (Default)
- "e" = Base location is End of the file
- "c" = Base location is the current location
Return Value
Success: Returns 1
Failure: Returns 0 if error occurs.
Remarks
N/A
Example
$File = FileOpen("MyFile.txt", "w"); If(isVarObj($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" ); FileSeek( $File, 0 ); FileWrite( $File, "Replace Line 1" ); FileClose( $File ); }