Difference between revisions of "ObjectType:file"
Jump to navigation
Jump to search
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | == | + | == Overview == |
+ | {{ObjectType-Vitals|file|[[LavishScript]]|none|The full path and filename to this file|file|no|void *}} | ||
== Members == | == Members == | ||
*[[ObjectType:bool|bool]] '''Open''': TRUE if the file is open | *[[ObjectType:bool|bool]] '''Open''': TRUE if the file is open | ||
− | *filepath '''Path''': Full path to this file | + | *[[ObjectType:filepath|filepath]] '''Path''': Full path to this file |
*[[ObjectType:string|string]] '''Filename''': Filename of this file | *[[ObjectType:string|string]] '''Filename''': Filename of this file | ||
*[[ObjectType:string|string]] '''Read''': Reads a line from this file, up to 1024 characters long (result includes carriage return) | *[[ObjectType:string|string]] '''Read''': Reads a line from this file, up to 1024 characters long (result includes carriage return) | ||
Line 14: | Line 15: | ||
== Methods == | == Methods == | ||
*'''SetFilename['''filename''']''': Sets the full path and filename. Only valid while file is closed. | *'''SetFilename['''filename''']''': Sets the full path and filename. Only valid while file is closed. | ||
− | *'''Open''': Opens the file | + | *'''Open''': Opens the file in read-write mode. Creates the file if it does not exist. |
− | *'''Open[readonly]''': Opens the file in read-only mode | + | *'''Open[readonly]''': Opens the file in read-only mode. Does not create the file if it does not exist. |
*'''Close''': Closes the file | *'''Close''': Closes the file | ||
*'''Write['''text''']''': Writes the given text to the file | *'''Write['''text''']''': Writes the given text to the file | ||
Line 32: | Line 33: | ||
function main() | function main() | ||
{ | { | ||
− | + | variable binary Buffer | |
− | + | variable file File=test.dat | |
echo Filename=${File.Path}${File.Filename} | echo Filename=${File.Path}${File.Filename} | ||
Line 57: | Line 58: | ||
echo Closed | echo Closed | ||
− | + | variable filepath FP="c:/program files/innerspace/scripts" | |
echo FileExists[test.iss] = ${FP.FileExists[test.iss]} | echo FileExists[test.iss] = ${FP.FileExists[test.iss]} | ||
echo Path = ${FP.Path} | echo Path = ${FP.Path} | ||
Line 114: | Line 115: | ||
WriteBinary=TRUE | WriteBinary=TRUE | ||
Closed | Closed | ||
− | |||
− | |||
− | |||
− | |||
− | |||
== See Also == | == See Also == | ||
− | + | {{LavishScript:ObjectType}} | |
− | |||
− | |||
− |
Latest revision as of 16:37, 8 July 2018
Overview
file | |
Defined By | LavishScript |
Inherits | none |
Reduces To | The full path and filename to this file |
Variable Object Type | file |
Uses Sub-Types | no |
C/C++ Type | void * |
Members
- bool Open: TRUE if the file is open
- filepath Path: Full path to this file
- string Filename: Filename of this file
- string Read: Reads a line from this file, up to 1024 characters long (result includes carriage return)
- string Read[#]: Reads a line from this file, up to # characters long (result includes carriage return)
- int ReadBinary[binary variable,#]: Reads # bytes into the specified buffer. Result is the number of bytes read.
- int Position: Current position within the file
- int Size: Size of the file
- bool EOF: TRUE if the previous Read or ReadBinary hit the end of the file
Methods
- SetFilename[filename]: Sets the full path and filename. Only valid while file is closed.
- Open: Opens the file in read-write mode. Creates the file if it does not exist.
- Open[readonly]: Opens the file in read-only mode. Does not create the file if it does not exist.
- Close: Closes the file
- Write[text]: Writes the given text to the file
- WriteBinary[binary variable,#]: Writes # bytes from the given buffer variable to the file
- Seek[#]: Seeks to the specified position within the file
- SeekEnd: Seeks to the end of the file
- Skip[#]: Skips # bytes within the file
- Truncate: Truncates the file at the current position (all data after this point in the file is removed)
- Flush: Forces any pending writes to disk. Writes may otherwise be buffered until the file is closed, or if the file is open for both reading and writing, until a read operation
Returns
The full path and filename to this file
Examples
- Example code
function main() { variable binary Buffer variable file File=test.dat echo Filename=${File.Path}${File.Filename} echo Opened=${File:Open(exists)} echo Write=${File:Write["Line One...\n"](exists)} echo Position=${File.Position} echo Write=${File:Write["Line Two!\n"](exists)} echo Position=${File.Position} echo Truncate=${File:Truncate(exists)} echo Size=${File.Size} File:Close echo Closed echo Filename=${File.Path}${File.Filename} echo Opened Readonly=${File:Open[readonly](exists)} echo Write=${File:Write["Overwriting Line One?\n"](exists)} echo Position=${File.Position} echo Read=${File.Read} echo Position=${File.Position} echo Read=${File.Read} echo Position=${File.Position} File:Close echo Closed variable filepath FP="c:/program files/innerspace/scripts" echo FileExists[test.iss] = ${FP.FileExists[test.iss]} echo Path = ${FP.Path} echo PathExists = ${FP.PathExists} echo AbsolutePath = ${FP.AbsolutePath} echo Filename=${File.Path}${File.Filename} echo Opened Readonly=${File:Open[readonly](exists)} echo ReadBinary=${File.ReadBinary[Buffer,${File.Size}]} echo Null terminating... Buffer.Byte[${File.Size}]:Set[0] echo String=${Buffer.String[1]} File:Close echo Closed echo Filename=${File.Path}${File.Filename} echo Opened=${File:Open(exists)} Buffer.Int[1]:Set[12345678] echo WriteBinary=${File:WriteBinary[Buffer,${File.Size}](exists)} File:Close echo Closed }
- Output
Filename=C:/Program Files/InnerSpace/test.dat Opened=TRUE Write=TRUE Position=12 Write=TRUE Position=22 Truncate=TRUE Size=22 Closed Filename=C:/Program Files/InnerSpace/test.dat Opened Readonly=TRUE Write=NULL Position=0 Read=Line One... Position=12 Read=Line Two! Position=22 Closed FileExists[test.iss] = TRUE Path = c:/program files/innerspace/scripts PathExists = TRUE AbsolutePath = c:/program files/innerspace/scripts Filename=C:/Program Files/InnerSpace/test.dat Opened Readonly=TRUE ReadBinary=22 Null terminating... String=NULL Closed Filename=C:/Program Files/InnerSpace/test.dat Opened=TRUE WriteBinary=TRUE Closed
See Also
LavishScript Object Types
- Text
- string - mutablestring - unistring
- Numbers
- byte - float - float64 - int - uint - int64
- Boolean (TRUE/FALSE)
- bool
- Pointers
- boolptr - byteptr - floatptr - float64ptr - intptr - uintptr - int64ptr - rgbptr - stringptr
- Containers
- objectcontainer - array - index - collection - queue - stack - set - variablescope
- JSON
- jsonobject - jsonarray - jsonvaluecontainer - jsonvalue
- Iteration
- iterator - jsoniterator
- Date/Time
- time
- File Handling
- filepath - file - filelist - filelistentry
- Tasks
- lavishmachine - Accessed via the Top-Level Object LMAC
- task - tasklibrary - taskmanager - tasktype - taskpulseargs - elmactaskstate