system.file - Palamecia/mint GitHub Wiki

Module

load system.file

This module provides the System.File class which allow interactions with the filesystem for one specific file.

Packages

Enums

System.File.Permission

This enum is used by the System.File.permission function to report the permissions and ownership of a file. The values may be OR-ed together to test multiple permissions and ownership values.

Constant Value Description
ExecGroup 0x0010 The file is executable by the group.
ExecOther 0x0001 The file is executable by anyone.
ExecOwner 0x1000 The file is executable by the owner of the file.
ExecUser 0x0100 The file is executable by the user.
ReadGroup 0x0040 The file is readable by the group.
ReadOther 0x0004 The file is readable by anyone.
ReadOwner 0x4000 The file is readable by the owner of the file.
ReadUser 0x0400 The file is readable by the user.
WriteGroup 0x0020 The file is writable by the group.
WriteOther 0x0002 The file is writable by anyone.
WriteOwner 0x2000 The file is writable by the owner of the file.
WriteUser 0x0200 The file is writable by the user.

Classes

System.File

This class provides informations about a file in the file system like path, size, rights, ... It also provides an interface to read or write data from/to the file.

This type is not copyable

Members

Modifiers Member Description
+ const << Writes the string data to the stream, and returns a reference to the System...
+ const >> Reads a word from the stream and stores it in data, then returns a referenc...
+ enum Permission This enum is used by the System.File.permission function to report the permis...
+ const absolutePath Returns an absolute path including the file name.
+ const atEnd Returns true if the end of the file has been reached; otherwise returns f...
+ const baseName Returns the base name of the file without the path.
+ const birthTime Returns the date when the file was created / born.
- const clone Disable object copy.
+ const close Flushes buffered modifications and closes the file. An instance of Exception....
- final codec Internal file codec.
+ const completeBaseName Returns the base name of the file without the path including each parts after...
+ const completeSuffix Returns the suffix (extension) of the file including each parts after a . (...
+ const copy Creates a copy named target of the the file currently specified by this obj...
- final d_ptr Object data.
+ const delete Destroy the instance and close the file descriptor if it is open.
+ const exists Returns true if the file exists; otherwise returns false.
+ const flush Flushes any buffered data to the file. An instance of Exception.SystemError i...
- @ g_lib Global library handle.
+ const getCodec Returns the codec that is current assigned to the file. If the file use the d...
+ const getDescriptor Returns the file descriptor openned by this object or none if the file is n...
+ const getDirectory Returns the path of the object's parent directory as a System.Directory object.
+ const getGroup Returns the group of the file. On systems where files do not have groups, or ...
+ const getGroupId Returns the id of the group the file belongs to.
+ const getName Returns the name of the file, excluding the path.
+ const getOwner Returns the owner of the file. On systems where files do not have owners, or ...
+ const getOwnerId Returns the id of the owner of the file.
+ const getPath Returns the file name, including the path (which may be absolute or relative).
+ const isAbsolute Returns true if the file path is absolute, otherwise returns false (i.e. ...
+ const isBundle Returns true if this object points to a bundle or to a symbolic link to a b...
+ const isDirectory Returns true if this object points to a directory or to a symbolic link to ...
+ const isExecutable Returns true if the file is executable; otherwise returns false.
+ const isFile Returns true if this object points to a regular file or to a symbolic link ...
+ const isHidden Returns true if this is a hidden file; otherwise returns false.
+ const isOpen Returns true if the file is open; otherwise returns false.
+ const isReadable Returns true if the user can read the file; otherwise returns false.
+ const isRelative Returns true if the file path is relative, otherwise returns false (i.e. ...
+ const isRoot Returns true if the object points to a directory or to a symbolic link to a...
+ const isSymlink Returns true if this object points to a symbolic link; otherwise returns ``...
+ const isWritable Returns true if the user can write to the file; otherwise returns false.
+ const lastModified Returns the date when the file was last modified.
+ const lastRead Returns the date when the file was last read (accessed).
+ const link Creates a link named target that points to the file currently specified by ...
+ const makeAbsolute Converts the file's path to an absolute path if it is not already in that form.
+ const new Creates a new instance pointing to the file specified by the given path.
+ const open Opens the file using mode, returning true if successful; otherwise fals...
- final path Internal file path.
+ const permission Tests for file permissions. The permissions argument can be several flags of ...
+ const read Reads all remaining data from the file, and returns it as a string. An instan...
+ const readChar Reads the next character from the file, and returns it as a string. Data is r...
+ const readDataStream Reads all remaining data from the file, and returns it as a Serializer.DataSt...
+ const readLine Reads the next line from the file, and returns it as a string. Data is read u...
+ const readLines Returns an iterator on each remaining lines of the file. An instance of Excep...
+ const readUInt8 Reads the next byte from the file, and returns it as a uint8. An instance of ...
+ const readWord Reads a word from the file, and returns it as a string. Words are separated b...
+ const remove Removes the file currently specified by this object. An instance of Exception...
+ const rename Renames the file currently specified by this object to name. An instance of...
+ const seek Sets the position that data is written to or read from to pos. If pos is ...
+ const setCodec Sets the codec for this file to codec. The codec is used for decoding any d...
+ const size Returns the file size in bytes. If the file does not exist or cannot be fetch...
+ const suffix Returns the suffix (extension) of the file.
+ const symlinkTarget Returns the absolute path to the file or directory a symbolic link points to,...
+ const tell Returns the position that data is written to or read from. An instance of Exc...
+ const write Writes the content of data to the file. Returns the number of bytes that we...

Functions

Descriptions

System.File.<<

def (self, data)

Writes the string data to the stream, and returns a reference to the System.File. The string is first encoded using the assigned codec (the default is UTF-8) before it is written to the stream.

An instance of Exception.SystemError is raised on error.

System.File.>>

def (self, data)

Reads a word from the stream and stores it in data, then returns a reference to the stream. Words are separated by whitespace (i.e., all characters for which isSpace returns true).

Leading whitespace are skipped.

An instance of Exception.SystemError is raised on error.

System.File.Permission.ExecGroup

0x0010

The file is executable by the group.

System.File.Permission.ExecOther

0x0001

The file is executable by anyone.

System.File.Permission.ExecOwner

0x1000

The file is executable by the owner of the file.

System.File.Permission.ExecUser

0x0100

The file is executable by the user.

System.File.Permission.ReadGroup

0x0040

The file is readable by the group.

System.File.Permission.ReadOther

0x0004

The file is readable by anyone.

System.File.Permission.ReadOwner

0x4000

The file is readable by the owner of the file.

System.File.Permission.ReadUser

0x0400

The file is readable by the user.

System.File.Permission.WriteGroup

0x0020

The file is writable by the group.

System.File.Permission.WriteOther

0x0002

The file is writable by anyone.

System.File.Permission.WriteOwner

0x2000

The file is writable by the owner of the file.

System.File.Permission.WriteUser

0x0200

The file is writable by the user.

System.File.absolutePath

def (const self)

Returns an absolute path including the file name.

System.File.atEnd

def (const self)

Returns true if the end of the file has been reached; otherwise returns false.

An instance of Exception.SystemError is raised on error.

System.File.baseName

def (const self)

Returns the base name of the file without the path.

System.File.birthTime

def (const self)

Returns the date when the file was created / born.

System.File.clone

none

Disable object copy.

System.File.close

def (self)

Flushes buffered modifications and closes the file.

An instance of Exception.SystemError is raised on error.

System.File.codec

null

Internal file codec.

System.File.completeBaseName

def (const self)

Returns the base name of the file without the path including each parts after a . (dot) character before the last suffix.

System.File.completeSuffix

def (const self)

Returns the suffix (extension) of the file including each parts after a . (dot) character after the base name.

System.File.copy

def (self, target)

Creates a copy named target of the the file currently specified by this object.

An instance of Exception.SystemError is raised on error.

System.File.d_ptr

null

Object data.

System.File.delete

def (self)

Destroy the instance and close the file descriptor if it is open.

System.File.exists

def (const self)

Returns true if the file exists; otherwise returns false.

System.File.flush

def (self)

Flushes any buffered data to the file.

An instance of Exception.SystemError is raised on error.

System.File.g_lib

lib ('libmint-system')

Global library handle.

System.File.getCodec

def (const self)

Returns the codec that is current assigned to the file. If the file use the default codec (UTF-8), null is returned.

System.File.getDescriptor

def (const self)

Returns the file descriptor openned by this object or none if the file is not oppened.

System.File.getDirectory

def (const self)

Returns the path of the object's parent directory as a System.Directory object.

System.File.getGroup

def (const self)

Returns the group of the file. On systems where files do not have groups, or if an error occurs, an empty string is returned.

System.File.getGroupId

def (const self)

Returns the id of the group the file belongs to.

System.File.getName

def (const self)

Returns the name of the file, excluding the path.

System.File.getOwner

def (const self)

Returns the owner of the file. On systems where files do not have owners, or if an error occurs, an empty string is returned.

System.File.getOwnerId

def (const self)

Returns the id of the owner of the file.

System.File.getPath

def (const self)

Returns the file name, including the path (which may be absolute or relative).

System.File.isAbsolute

def (const self)

Returns true if the file path is absolute, otherwise returns false (i.e. the path is relative).

System.File.isBundle

def (const self)

Returns true if this object points to a bundle or to a symbolic link to a bundle on macOS and iOS; otherwise returns false.

System.File.isDirectory

def (const self)

Returns true if this object points to a directory or to a symbolic link to a directory; otherwise returns false.

System.File.isExecutable

def (const self)

Returns true if the file is executable; otherwise returns false.

System.File.isFile

def (const self)

Returns true if this object points to a regular file or to a symbolic link to a regular file. Returns false if the object points to something which isn't a file, such as a directory.

System.File.isHidden

def (const self)

Returns true if this is a hidden file; otherwise returns false.

System.File.isOpen

def (const self)

Returns true if the file is open; otherwise returns false.

System.File.isReadable

def (const self)

Returns true if the user can read the file; otherwise returns false.

System.File.isRelative

def (const self)

Returns true if the file path is relative, otherwise returns false (i.e. the path is absolute).

System.File.isRoot

def (const self)

Returns true if the object points to a directory or to a symbolic link to a directory which is the root directory; otherwise returns false.

System.File.isSymlink

def (const self)

Returns true if this object points to a symbolic link; otherwise returns false.

System.File.isWritable

def (const self)

Returns true if the user can write to the file; otherwise returns false.

System.File.lastModified

def (const self)

Returns the date when the file was last modified.

System.File.lastRead

def (const self)

Returns the date when the file was last read (accessed).

System.File.link

def (self, target)

Creates a link named target that points to the file currently specified by this object.

An instance of Exception.SystemError is raised on error.

System.File.makeAbsolute

def (self)

Converts the file's path to an absolute path if it is not already in that form.

System.File.new

def (self, path)

Creates a new instance pointing to the file specified by the given path.

System.File.open

def (self, mode = 'r')

Opens the file using mode, returning true if successful; otherwise false.

The mode parameter can be one of the following strings:

String Meaning
'r' Open file for input operations. The file must exist.
'r+' Open a file for update (both for input and output). The file must exist.
'w' Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.
'w+' Create an empty file and open it for update (both for input and output). If a file with the same name already exists its contents are discarded and the file is treated as a new empty file.
'a' Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. The file is created if it does not exist.
'a+' Open a file for update (both for input and output) with all output operations writing data at the end of the file. The file is created if it does not exist.

The 'b' character can be added at the second position of any string to open the file in binary mode.

An instance of Exception.SystemError is raised on error.

System.File.path

''

Internal file path.

System.File.permission

def (const self, permissions)

Tests for file permissions. The permissions argument can be several flags of type System.File.Permission OR-ed together to check for permission combinations.

System.File.read

def (self)

Reads all remaining data from the file, and returns it as a string.

An instance of Exception.SystemError is raised on error.

System.File.readChar

def (self)

Reads the next character from the file, and returns it as a string. Data is read until a valid character is read or if the end of file is detected.

An instance of Exception.SystemError is raised on error.

System.File.readDataStream

def (self)

Reads all remaining data from the file, and returns it as a Serializer.DataStream.

[!IMPORTANT] The purpose of this method is to read raw data, to read text use System.File.read.

An instance of Exception.SystemError is raised on error.

System.File.readLine

def (self)

Reads the next line from the file, and returns it as a string. Data is read until a '\n' character is read or if the end of file is detected.

An instance of Exception.SystemError is raised on error.

System.File.readLines

def (self)

Returns an iterator on each remaining lines of the file.

An instance of Exception.SystemError is raised on error.

System.File.readUInt8

def (self)

Reads the next byte from the file, and returns it as a uint8.

An instance of Exception.SystemError is raised on error.

System.File.readWord

def (self)

Reads a word from the file, and returns it as a string. Words are separated by whitespace (i.e., all characters for which isSpace returns true).

Leading whitespace are skipped.

An instance of Exception.SystemError is raised on error.

System.File.remove

def (self)

Removes the file currently specified by this object.

An instance of Exception.SystemError is raised on error.

System.File.rename

def (self, name)

Renames the file currently specified by this object to name.

An instance of Exception.SystemError is raised on error.

System.File.seek

def (self, pos)

Sets the position that data is written to or read from to pos.

If pos is in the range 0...self.size(), the position is moved relatively from the begin of the file.

If pos is in the range -1..-self.size(), the position is moved relatively from the end of the file.

An instance of Exception.SystemError is raised on error.

System.File.setCodec

def (self, codec)

Sets the codec for this file to codec. The codec is used for decoding any data that is read from the file, and for encoding any data that is written. By default, UTF-8 is used. This default behaviour can be re enabled by setting a null codec.

System.File.size

def (const self)

Returns the file size in bytes. If the file does not exist or cannot be fetched, 0 is returned.

System.File.suffix

def (const self)

Returns the suffix (extension) of the file.

System.File.symlinkTarget

def (const self)

Returns the absolute path to the file or directory a symbolic link points to, or the object's path if it is not a symbolic link.

System.File.tell

def (const self)

Returns the position that data is written to or read from.

An instance of Exception.SystemError is raised on error.

System.File.write

def (self, data)

Writes the content of data to the file. Returns the number of bytes that were actually written. The content of data is converted to string using the codec set by System.File.setCodec or to an UTF-8 string by default.

An instance of Exception.SystemError is raised on error.

System.open

def (path, mode = 'r')

Creates a new System.File to represent the file with the specified path. The file is then opened with the given mode. Returns the file on success; otherwise returns null.