Provides an interface for file input/output. FileOpen() returns an object of this type.
`n
or `r`n
depending on the flags used to open the file. Advances the file pointer.File.Pos := Distance
.Pos := File.Pos
.Pos := File.Tell()
or File.Seek(Distance)
.Reads a string of characters from the file and advances the file pointer.
String := File.Read(Characters)
Returns a string.
Writes a string of characters to the file and advances the file pointer.
File.Write(String)
Returns the number of bytes (not characters) that were written.
Reads a line of text from the file and advances the file pointer.
TextLine := File.ReadLine()
Returns a line of text. This may include `n
, `r`n
or `r
depending on the file and EOL flags used to open the file.
Lines up to 65,534 characters long can be read. If the length of a line exceeds this, the remainder of the line is returned by subsequent calls to this method.
Writes a string of characters followed by `n
or `r`n
depending on the flags used to open the file. Advances the file pointer.
File.WriteLine(String)
Returns the number of bytes (not characters) that were written.
Reads a number from the file and advances the file pointer.
Num := File.ReadNumType()
NumType is either UInt, Int, Int64, Short, UShort, Char, UChar, Double, or Float. These type names have the same meanings as with DllCall().
Returns a number if successful, otherwise an empty string.
If a Try statement is active and no bytes were read, an exception is thrown. However, no exception is thrown if at least one byte was read, even if the size of the given NumType is greater than the number of bytes read. Instead, the missing bytes are assumed to be zero.
Writes a number to the file and advances the file pointer.
File.WriteNumType(Num)
NumType is either UInt, Int, Int64, Short, UShort, Char, UChar, Double, or Float. These type names have the same meanings as with DllCall().
Returns the number of bytes that were written. For instance, WriteUInt returns 4 if successful.
Reads raw binary data from the file into memory and advances the file pointer.
File.RawRead(VarOrAddress, Bytes)
Returns the number of bytes that were read.
If a Try statement is active and Bytes is non-zero but no bytes were read, an exception is thrown. AtEOF can be used to avoid this, if needed.
Writes raw binary data to the file and advances the file pointer.
File.RawWrite(VarOrAddress, Bytes)
Returns the number of bytes that were written.
Moves the file pointer.
File.Seek(Distance , Origin := 0) File.Position := Distance File.Pos := Distance
Starting point for the file pointer move. Must be one of the following:
If omitted, Origin defaults to SEEK_END when Distance is negative and SEEK_SET otherwise.
Returns a non-zero value if successful, otherwise zero.
Returns the current position of the file pointer, where 0 is the beginning of the file.
Pos := File.Tell()
Pos := File.Position
Pos := File.Pos
Closes the file, flushes any data in the cache to disk and releases the share locks.
File.Close()
Although the file is closed automatically when the object is freed, it is recommended to close the file as soon as possible.
Retrieves or sets the size of the file.
FileSize := File.Length
File.Length := NewSize
FileSize and NewSize is the size of the file, in bytes.
This property should be used only with an actual file. If the File object was created from a handle to a pipe, it may return the amount of data currently available in the pipe's internal buffer, but this behaviour is not guaranteed.
Retrieves a non-zero value if the file pointer has reached the end of the file, otherwise zero.
IsAtEOF := File.AtEOF
This property should be used only with an actual file. If the File object was created from a handle to a non-seeking device such as a console buffer or pipe, the returned value may not be meaningful, as such devices do not logically have an "end of file".
Retrieves or sets the text encoding used by this file object.
RetrievedEncoding := File.Encoding
File.Encoding := NewEncoding
RetrievedEncoding and NewEncoding is a numeric code page identifier (see MSDN) or one of the following strings:
UTF-8
: Unicode UTF-8, equivalent to CP65001.UTF-16
: Unicode UTF-16 with little endian byte order, equivalent to CP1200.CPnnn
: a code page with numeric identifier nnn.RetrievedEncoding is never a value with the -RAW
suffix, regardless of how the file was opened or whether it contains a byte order mark (BOM). Setting NewEncoding never causes a BOM to be added or removed, as the BOM is normally written to the file when it is first created.
[v1.1.15.04+]: Setting NewEncoding to UTF-8-RAW
or UTF-16-RAW
is valid, but the -RAW
suffix is ignored. In earlier versions, UTF-8-RAW
and UTF-16-RAW
behaved like an invalid 8-bit encoding, causing all non-ASCII characters to be discarded. This only applies to File.Encoding
, not FileOpen().
Returns a system file handle, intended for use with DllCall(). See CreateFile.
File.__Handle
File objects internally buffer reads or writes. If data has been written into the object's internal buffer, it is committed to disk before the handle is returned. If the buffer contains data read from file, it is discarded and the actual file pointer is reset to the logical position indicated by File.Pos
.