Monkey Documentation

Module os

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


Constants:
  • FILETYPE_DIR : Int
  • FILETYPE_FILE : Int
  • FILETYPE_NONE : Int
Functions:

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.


Function 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.

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.

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

Copies a file from srcpath to dstpath.

Function CreateDir : Int ( path:String )

Create a new directory at 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!

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

Deletes the directory at path.

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

Function DeleteFile : Int ( path:String )

Deletes the specified file.

Function Execute : Int ( cmd:String )

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

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.

Function ExtractDir : String ( path:String )

Extracts and returns the directory of a file system path.

Function ExtractExt : String ( path:String )

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

Function FileSize : Int ( path:String )

Return the length of a file, in bytes.

Function FileTime : Int ( path:String )

Returns the time the file at path was last modified.

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.

Function GetEnv : String ( name:String )

Gets an environment variable.

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.

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.

Function LoadString : String ( path:String )

Loads a string from the file at path.

Function RealPath : String ( path:String )

Returns the real, or 'absolute', file system path corresponding to the given 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.

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

Sets an environment variable.

Function StripAll : String ( path:String )

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

Function StripDir : String ( path:String )

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

Function StripExt : String ( path:String )

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