Cerberus X Documentation

Module os

The os module provides miscellaneous operating system functionality, such as file, directory and environment variable access. More...

Declarations

Constants
FILETYPE_DIR : Int
FILETYPE_FILE : Int
FILETYPE_NONE : Int
Functions
AppArgs : String[] () Returns the application startup parameters.
AppPath : String () Returns the file system path of the currently running application.
ChangeDir : Int ( path:String ) Changes the current directory of the running application.
CopyDir : Int ( srcpath:String, dstpath:String, recursive:Bool, hidden:Bool ) Copies the directory at srcpath to dstpath, creating dstpath if necessary.
CopyFile : Int ( src:String, dst:String ) Copies a file from srcpath to dstpath.
CreateDir : Int ( path:String ) Create a new directory at path.
CurrentDir : String () Returns the current directory of the currently running application.
DeleteDir : Int ( path:String ) Deletes the directory at path.
DeleteDir : Int ( path:String, recursive:Bool ) Deletes the directory at path.
DeleteFile : Int ( path:String ) Deletes the specified file.
Execute : Int ( cmd:String ) Executes a shell command and returns the result.
ExitApp : Int ( retcode:Int ) Exits the application with the given return code.
ExtractDir : String ( path:String ) Extracts and returns the directory of a file system path.
ExtractExt : String ( path:String ) Extracts and returns the file type extension of a file system path.
FileSize : Int ( path:String ) Return the length of a file, in bytes.
FileTime : Int ( path:String ) Returns the time the file at path was last modified.
FileType : Int ( path:String ) Returns an integer representing the type of a file, one of: 0 for no file, 1 for a normal file, 2 for a directory.
GetEnv : String ( name:String ) Gets an environment variable.
HostOS : String () Returns a string describing the host operating system.
LoadDir : String[] ( path:String ) Loads the file names in the directory specified by path into a string array.
LoadDir : String[] ( path:String, recursive:Bool, hidden:Bool=False ) Loads the file names in the directory specified by path into a string array.
LoadString : String ( path:String ) Loads a string from the file at path.
RealPath : String ( path:String ) Returns the real, or 'absolute', file system path corresponding to the given path.
SaveString : Int ( str:String, path:String ) Saves str to a file specified by path.
SetEnv : Int ( name:String, value:String ) Sets an environment variable.
StripAll : String ( path:String ) Removes both the directory and file extension from a file system path, returning just the file name.
StripDir : String ( path:String ) Removes the directory from a file system path, and returns the file name and extension.
StripExt : String ( path:String ) Extracts and returns the file extension of a file system path.

Detailed Discussion

The os module provides miscellaneous operating system functionality, such as file, directory and environment variable access.

The os module also includes several string processing functions for extracting various components from file system paths such as directory and file extension.

IMPORTANT: The os module is currently only available for the glfw and stdcpp targets.


Constants Documentation

Const FILETYPE_DIR : Int
Const FILETYPE_FILE : Int
Const FILETYPE_NONE : Int

Functions Documentation

Function AppArgs : String[] ()

Returns the application startup parameters.

Function AppPath : String ()

Returns the file system path of the currently running application.

Function ChangeDir : Int ( path:String )

Changes the current directory of the running application.

Parameters

path - file system path of directory.

Function CopyDir : Int ( srcpath:String, dstpath:String, recursive:Bool, hidden:Bool )

Copies the directory at srcpath to dstpath, creating dstpath if necessary.

If recursive is True, then subdirectories are also copied.

If hidden is True, then hidden files - files starting with a dot - are also copied.

Parameters

srcpath - file system path of source directory.

dstpath - file system path of destination directory.

recursive - flag indicating whether subdirectories should also be copied.

hidden - flag indicating whther hidden files should also be copied.

Function CopyFile : Int ( src:String, dst:String )

Copies a file from srcpath to dstpath.

Parameters

srcpath - file system path of source file.

dstpath - file system path of destination file.

Function CreateDir : Int ( path:String )

Create a new directory at path.

Parameters

path - a file system path.

Function CurrentDir : String ()

Returns the current directory of the currently running application.

Function DeleteDir : Int ( path:String )

Deletes the directory at path.

If recursive is True, then subdirectories are also deleted - use with care!

Parameters

path - file system path of directory to delete.

recursive - a flag indicating whether subdirectories should also be deleted.

Function DeleteDir : Int ( path:String, recursive:Bool )

Deletes the directory at path.

If recursive is True, then subdirectories are also deleted - use with care!

Parameters

path - file system path of directory to delete.

recursive - a flag indicating whether subdirectories should also be deleted.

Function DeleteFile : Int ( path:String )

Deletes the specified file.

Parameters

path - a file system path.

Function Execute : Int ( cmd:String )

Executes a shell command and returns the result. This is generally 0 for success, or non-0 for failure.

Parameters

cmd - command to execute.

Function ExitApp : Int ( retcode:Int )

Exits the application with the given return code.

In general, ExitApp should return 0 if successful, or <0 upon failure.

Parameters

retcode - application return code.

Function ExtractDir : String ( path:String )

Extracts and returns the directory of a file system path.

Parameters

path - a file system path.

Function ExtractExt : String ( path:String )

Extracts and returns the file type extension of a file system path.

Parameters

path - a file system path.

Function FileSize : Int ( path:String )

Return the length of a file, in bytes.

Parameters

path - a file system path.

Function FileTime : Int ( path:String )

Returns the time the file at path was last modified.

Parameters

path - a file system path.

Function FileType : Int ( path:String )

Returns an integer representing the type of a file, one of: 0 for no file, 1 for a normal file, 2 for a directory.

Parameters

path - a file system path.

Function GetEnv : String ( name:String )

Gets an environment variable.

Parameters

name - name of environment var.

Function HostOS : String ()

Returns a string describing the host operating system. The returned value will be one of:

HostOSOperating system
winntWindows
macosMacOS
linuxLinux
Function LoadDir : String[] ( path:String )

Loads the file names in the directory specified by path into a string array.

If recursive is True, LoadDir will also load file names in subdirectories, but will not add subdirectories to the output string array.

If hidden is True, then hidden files - files starting with a dot - are also loaded.

Parameters

path - a file system path.

recursive - a flag indicating whether subdirectories should also be loaded.

hidden - a flag indicating whether hidden files should also be loaded.

Function LoadDir : String[] ( path:String, recursive:Bool, hidden:Bool=False )

Loads the file names in the directory specified by path into a string array.

If recursive is True, LoadDir will also load file names in subdirectories.

If hidden is True, then hidden files - files starting with a dot - are also loaded.

Parameters

path - a file system path.

recursive - a flag indicating whether subdirectories should also be loaded.

hidden - a flag indicating whether hidden files should also be loaded.

Function LoadString : String ( path:String )

Loads a string from the file at path.

Parameters

path - a file system path.

Function RealPath : String ( path:String )

Returns the real, or 'absolute', file system path corresponding to the given path.

Parameters

path - a file system path.

Function SaveString : Int ( str:String, path:String )

Saves str to a file specified by path.

If a file already exists at path, it will be overwritten.

Parameters

str - a string value.

path - a file system path.

Function SetEnv : Int ( name:String, value:String )

Sets an environment variable.

Parameters

name - name of environment var.

value - value to set environment var to.

Function StripAll : String ( path:String )

Removes both the directory and file extension from a file system path, returning just the file name.

Parameters

path - a file system path.

Function StripDir : String ( path:String )

Removes the directory from a file system path, and returns the file name and extension.

Parameters

path - a file system path.

Function StripExt : String ( path:String )

Extracts and returns the file extension of a file system path.

Parameters

path - a file system path.