Module filekit

Wrapper around LuaFileSystem along with other functions.

The objective of this is really just simplifying the methods used by lfs and collect other methods. It also incorporates compatibility with the ComputerCraft FS API

Info:

  • Copyright: 11.07.2019
  • Author: daelvn

Functions

currentDir () Represents the current working directory
changeDir (path) Changes the current working directory
getDevice (path) Gets the device of the inode.
getInode (path) Gets the inode of a file or folder.
getMode (path) Gets the mode of a node.
getLinks (path) Gets the number of hard links to the file.
getUID (path) Gets the user ID of the owner.
getGID (path) Gets the group ID of the owner.
getDeviceType (path) On Unix systems, gets the device type, for special file inodes.
getLastAccess (path) Gets the timestamp of last access.
getLastModification (path) Gets the timestamp of the last modification.
getLastChange (path) Gets the timestamp of the last status change.
getPermissions (path) Gets the permissions as a table.
getOctalPermissions (path) Gets the permissions as an octal number.
getBlocks (path) Get the blocks allocated for file (unix only)
getBlockSize (path) Get the optimal filesystem blocksize (unix only)
getLinkDevice (path) Gets the device of the inode (for links).
getLinkInode (path) Gets the inode of a link.
getLinkMode (path) Gets the mode of a link.
getLinkLinks (path) Gets the number of hard links to the link.
getLinkUID (path) Gets the user ID of the owner.
getLinkGID (path) Gets the group ID of the owner.
getLinkDeviceType (path) On Unix systems, getLinks the device type, for special link inodes.
getLinkLastAccess (path) Gets the timestamp of last access.
getLinkLastModification (path) Gets the timestamp of the last modification.
getLinkLastChange (path) Gets the timestamp of the last status change.
getLinkPermissions (path) Gets the permissions as a table.
getLinkOctalPermissions (path) Gets the permissions as an octal number.
getLinkBlocks (path) Get the blocks allocated for link (unix only)
getLinkBlockSize (path) Get the optimal linksystem blocksize (unix only)
list (path) Returns a list of all the files (including subdirectories but not their contents) contained in a directory, as a numerically indexed table.
ilist (path) List iterator (as lfs.dir)
list1 (path) Returns a list of all the files (including subdirectories), excluding ..
ilist1 (path) List iterator (as lfs.dir) using list1
safeOpen (path, mode) Returns a file handle, or if errored, a table with a field error that contains the error.
exists (path) Checks if a path refers to an existing file or directory.
isDir (path) Checks if a path refers to an existing directory.
isFile (path) Checks if a path refers to an existing file.
isLink (path) Checks if a path refers to an existing link.
isSocket (path) Checks if a path refers to an existing socket.
isPipe (path) Checks if a path refers to an existing pipe.
isCharDevice (path) Checks if a path refers to an existing char device.
isBlockDevice (path) Checks if a path refers to an existing block device.
isOther (path) Checks if a path refers to an existing node that is none of the other types.
isReadOnly (path) Checks if a path is read-only (i.e.
getName (path) Gets the final component of a pathname.
getDrive (path) Gets the storage medium holding a path, or nil if the path does not exist.
getSize (path) Gets the size of a file in bytes.
getLinkSize (path) Gets the size of a link in bytes.
getFreeSpace (path) Gets the remaining space on the drive containing the given directory.
makeDir (path) Makes a directory.
move (path, path) Moves a file or directory to a new location.
copy (path, path) Copies a file or directory to a new location.
delete (path) Deletes a file or directory.
combine (basePath, localPath) Combines two path components, returning a path consisting of the local path nested inside the base path.
open (path, mode) Opens a file so it can be read or written.
listAll (path) Lists all nodes in a directory recursively
find (wildcard) Searches the computer's files using wildcards.
getDir (path) Returns the parent directory of path.
link (fr, to) Creates a hard link.
symlink (fr, to) Creates a symbolic link.
touch (path, atime, mtime) Set access and modification times of a file.
lockDir (path, stale) Locks a directory.
lock (file, exclusive, start, length) Locks a file handle.
unlock (file, start, length) Unocks a file handle.
setMode (file, mode) Sets the writing mode for a file handle.
matchGlob (glob, path) Matches a compiled glob with a string
glob (path) Returns a list of paths matched by the globs
iglob (path) Glob as an iterator


Functions

currentDir ()
Represents the current working directory
changeDir (path)
Changes the current working directory

Parameters:

  • path string Changes the CWD to this path.

Returns:

    nil
getDevice (path)
Gets the device of the inode.

Parameters:

Returns:

    number Device number.
getInode (path)
Gets the inode of a file or folder.

Parameters:

Returns:

    number Inode number.
getMode (path)
Gets the mode of a node.

Parameters:

Returns:

    string Mode.
getLinks (path)
Gets the number of hard links to the file.

Parameters:

Returns:

    number Number of hard links.
getUID (path)
Gets the user ID of the owner. Always 0 on Windows.

Parameters:

Returns:

    number User ID.
getGID (path)
Gets the group ID of the owner. Always 0 on Windows.

Parameters:

Returns:

    number Group ID.
getDeviceType (path)
On Unix systems, gets the device type, for special file inodes. On Windows systems it equals getDevice path.

Parameters:

Returns:

    number Device type.
getLastAccess (path)
Gets the timestamp of last access.

Parameters:

Returns:

    number Last access time.
getLastModification (path)
Gets the timestamp of the last modification.

Parameters:

Returns:

    number Last modification time.
getLastChange (path)
Gets the timestamp of the last status change.

Parameters:

Returns:

    number Last status change time.
getPermissions (path)
Gets the permissions as a table.

Parameters:

Returns:

    table Permissions table.

Usage:

    print inspect getPermissions "main.moon"
    -- {
    --   owner = { read = true, write = true,  execute = false },
    --   group = { read = true, write = false, execute = false },
    --   world = { read = true, write = false, execute = false }
    -- }
getOctalPermissions (path)
Gets the permissions as an octal number.

Parameters:

Returns:

    number Permission number.
getBlocks (path)
Get the blocks allocated for file (unix only)

Parameters:

Returns:

    number Number of blocks allocated.
getBlockSize (path)
Get the optimal filesystem blocksize (unix only)

Parameters:

Returns:

    number Optimal size in bytes.
getLinkDevice (path)
Gets the device of the inode (for links).

Parameters:

  • path string Path to the link.

Returns:

    number Device number.
getLinkInode (path)
Gets the inode of a link.

Parameters:

  • path string Path to the link.

Returns:

    number Inode number.
getLinkMode (path)
Gets the mode of a link.

Parameters:

  • path string Path to the link.

Returns:

    string Mode.
getLinkLinks (path)
Gets the number of hard links to the link.

Parameters:

  • path string Path to the link.

Returns:

    number Number of hard links.
getLinkUID (path)
Gets the user ID of the owner. Always 0 on Windows.

Parameters:

  • path string Path to the link.

Returns:

    number User ID.
getLinkGID (path)
Gets the group ID of the owner. Always 0 on Windows.

Parameters:

  • path string Path to the link.

Returns:

    number Group ID.
getLinkDeviceType (path)
On Unix systems, getLinks the device type, for special link inodes. On Windows systems it equals getLinkDevice path.

Parameters:

  • path string Path to the link.

Returns:

    number Device type.
getLinkLastAccess (path)
Gets the timestamp of last access.

Parameters:

  • path string Path to the link.

Returns:

    number Last access time.
getLinkLastModification (path)
Gets the timestamp of the last modification.

Parameters:

  • path string Path to the link.

Returns:

    number Last modification time.
getLinkLastChange (path)
Gets the timestamp of the last status change.

Parameters:

  • path string Path to the link.

Returns:

    number Last status change time.
getLinkPermissions (path)
Gets the permissions as a table.

Parameters:

  • path string Path to the link.

Returns:

    table Permissions table.

Usage:

    print inspect getLinkPermissions "main.lnk.moon"
    -- {
    --   owner = { read = true, write = true,  execute = false },
    --   group = { read = true, write = false, execute = false },
    --   world = { read = true, write = false, execute = false }
    -- }
getLinkOctalPermissions (path)
Gets the permissions as an octal number.

Parameters:

  • path string Path to the link.

Returns:

    number Permission number.
getLinkBlocks (path)
Get the blocks allocated for link (unix only)

Parameters:

  • path string Path to the link.

Returns:

    number Number of blocks allocated.
getLinkBlockSize (path)
Get the optimal linksystem blocksize (unix only)

Parameters:

  • path string Path to the link.

Returns:

    number Optimal size in bytes.
list (path)
Returns a list of all the files (including subdirectories but not their contents) contained in a directory, as a numerically indexed table.

Parameters:

  • path string Path of the folder.

Returns:

    table Table of all the subnodes.
ilist (path)
List iterator (as lfs.dir)

Parameters:

  • path string Path of the folder.

Returns:

    function Iterator
list1 (path)
Returns a list of all the files (including subdirectories), excluding .. and .

Parameters:

  • path string Path of the folder.

Returns:

    table Table of all the subnodes.
ilist1 (path)
List iterator (as lfs.dir) using list1

Parameters:

  • path string Path of the folder.

Returns:

    function Iterator
safeOpen (path, mode)
Returns a file handle, or if errored, a table with a field error that contains the error.

Parameters:

  • path string Path to the file.
  • mode string Mode to open the file in.

Returns:

    File or table Either a file or a table containing error.
exists (path)
Checks if a path refers to an existing file or directory.

Parameters:

Returns:

    boolean Whether it exists or not.
isDir (path)
Checks if a path refers to an existing directory.

Parameters:

Returns:

    boolean Whether it is a directory or not.
isFile (path)
Checks if a path refers to an existing file.

Parameters:

Returns:

    boolean Whether it is a file or not.
isLink (path)
Checks if a path refers to an existing link.

Parameters:

Returns:

    boolean Whether it is a link or not.
isSocket (path)
Checks if a path refers to an existing socket.

Parameters:

Returns:

    boolean Whether it is a socket or not.
isPipe (path)
Checks if a path refers to an existing pipe.

Parameters:

Returns:

    boolean Whether it is a pipe or not.
isCharDevice (path)
Checks if a path refers to an existing char device.

Parameters:

Returns:

    boolean Whether it is a char device or not.
isBlockDevice (path)
Checks if a path refers to an existing block device.

Parameters:

Returns:

    boolean Whether it is a block device or not.
isOther (path)
Checks if a path refers to an existing node that is none of the other types.

Parameters:

Returns:

    boolean Whether it is other or not.
isReadOnly (path)
Checks if a path is read-only (i.e. cannot be modified). On non CC systems, it checks whether there's an "w" in the permissions string only, so don't rely too much on this.

Parameters:

Returns:

    boolean Whether it is readonly or not.
getName (path)
Gets the final component of a pathname.

Parameters:

  • path string Path to extract the filename from.

Returns:

    string The final part of the path.
getDrive (path)
Gets the storage medium holding a path, or nil if the path does not exist. This function is a stub and will always return nil. There's no simple way of knowing this.

Parameters:

  • path string Path to extract the mountpoint from.

Returns:

    string or nil Mountpoint.
getSize (path)
Gets the size of a file in bytes.

Parameters:

  • path string Path of the file.

Returns:

    number Size in bytes.
getLinkSize (path)
Gets the size of a link in bytes.

Parameters:

  • path string Path of the link.

Returns:

    number Size in bytes.
getFreeSpace (path)
Gets the remaining space on the drive containing the given directory. This function is a stub and will always return 0. There's no simple way of knowing this.

Parameters:

Returns:

    number Space left in bytes.
makeDir (path)
Makes a directory.

Parameters:

  • path string Path of the new directory.

Returns:

    nil
move (path, path)
Moves a file or directory to a new location.

Parameters:

  • path string Path of the new location.
  • path string Path of the new location.

Returns:

    nil
copy (path, path)
Copies a file or directory to a new location.

Parameters:

  • path string Path of the new location.
  • path string Path of the new location.

Returns:

    nil
delete (path)
Deletes a file or directory. Alias: remove

Parameters:

Returns:

    nil
combine (basePath, localPath)
Combines two path components, returning a path consisting of the local path nested inside the base path.

Parameters:

  • basePath string Path which contains the local path.
  • localPath string Contained path.

Returns:

    string Combined path.
open (path, mode)
Opens a file so it can be read or written.

Parameters:

  • path string Path to open.
  • mode string Mode to open the path with.

Returns:

    File File handle.
listAll (path)
Lists all nodes in a directory recursively

Parameters:

Returns:

    table List of nodes
find (wildcard)
Searches the computer's files using wildcards. On non CC systems, it only looks recursively in the current directory.

Parameters:

  • wildcard string Wildcard to match.

Returns:

    table Table of results.
getDir (path)
Returns the parent directory of path.

Parameters:

Returns:

    string Parent path.
link (fr, to)
Creates a hard link.

Parameters:

Returns:

    nil
symlink (fr, to)
Creates a symbolic link.

Parameters:

Returns:

    nil
touch (path, atime, mtime)
Set access and modification times of a file. The times should be in seconds and generated with os.time.

Parameters:

  • path string Path to the file.
  • atime number Access time (defaults to current time).
  • mtime number Modification time (defaults to atime or current time`).

Returns:

  1. true or nil Whether it was successful or not.
  2. string or nil If not successful, an error message.
lockDir (path, stale)
Locks a directory.

Parameters:

  • path string Path to the directory.
  • stale number Seconds until the lock is stale. Defaults to INT_MAX.

Returns:

  1. Lock or nil LuaFileSystem lock.
  2. string or nil If not successful, an error message.
lock (file, exclusive, start, length)
Locks a file handle.

Parameters:

  • file File File handle.
  • exclusive boolean Whether to lock exclusively or not. Defaults to false.
  • start number Starting point of the lock. Defaults to 0.
  • length number Length of the lock. Defaults to whole file.

Returns:

  1. true or nil Whether it was successful or not.
  2. string or nil If not successful, the error message.
unlock (file, start, length)
Unocks a file handle.

Parameters:

  • file File File handle.
  • start number Starting point of the lock. Defaults to 0.
  • length number Length of the lock. Defaults to whole file.

Returns:

  1. true or nil Whether it was successful or not.
  2. string or nil If not successful, the error message.
setMode (file, mode)
Sets the writing mode for a file handle.

Parameters:

  • file File File handle.
  • mode string "binary" or "text".

Returns:

  1. string or nil Previous mode for the file.
  2. string or nil If not successful, an error message.
matchGlob (glob, path)
Matches a compiled glob with a string

Parameters:

Returns:

    boolean Whether it matches or not
glob (path)
Returns a list of paths matched by the globs

Parameters:

Returns:

    table Table of globbed files
iglob (path)
Glob as an iterator

Parameters:

Returns:

    function Iterator
generated by LDoc 1.4.6 Last updated 2020-03-13 22:19:15