Module system

OS & filesystem operations

Functions

exe (cmd, split_output, suppress_log) Execute a shell command and return the result
os.copy (src, dest, overwrite, add_rootDir) Copy a file or directory
os.find (name, starting_directory) Find a file or directory
os.getcwd (file) Get the current working directory
os.is_dir (name) Check if a path is a directory
os.is_file (name) Check if a path is a file
os.listdir (dirname) List the contents of a directory
os.path_exists (path) Check if a path exists
os.path_join (...) Join one or more paths
os.read_line (f, n, add_rootDir) Read a single line from a file
os.read_lines (f, add_rootDir) Read all the lines in a file
os.sizeof (name, add_rootDir) Get the size of a file or directory
os.sleep (seconds) Sleep for a certain amount of seconds (millisecond precision)
os.write_line (line, n, name, add_rootDir) Write a single line to a file
os.write_lines (lines, name, mode, add_rootDir) Write multiple lines to a file


Functions

exe (cmd, split_output, suppress_log)
Execute a shell command and return the result

Parameters:

  • cmd string or table Unix command to execute. String commands are passed directly to the shell. Table commands are concatenated with the space character. So exe({'ls', 'mydir'}), exe{'ls', 'mydir'} and exe('ls mydir') are all equivalent.
  • split_output bool if false then returns the entire stdout as a string, otherwise a table of lines
  • suppress_log bool supress logging of executed command

Returns:

    table or string result of command in stdout
os.copy (src, dest, overwrite, add_rootDir)
Copy a file or directory

Parameters:

  • src string source to copy from (file or directory)
  • dest string desination to copy to (file or directory, but has to be a directory if src is a directory)
  • overwrite bool whether to overwrite any existing files/directories
  • add_rootDir bool should rootDir() be prepended to file name
os.find (name, starting_directory)
Find a file or directory

Parameters:

  • name string or table name of file/directory to search for. If you wish to search for a directory then you must pass a table as name. If a table is passed then it must be of the format {type=name, start=starting_directory}, where type is one of f, file, dir or d, and start is an optional value in the table.
  • starting_directory string directory in which to begin search (can drastically increase speed)

Returns:

    string absolute path if it exists, an empty string otherwise
os.getcwd (file)
Get the current working directory

Parameters:

  • file string (Optional) file name to append to end of path

Returns:

    string path of current working directory
os.is_dir (name)
Check if a path is a directory

Parameters:

Returns:

    boolean is the path a directory
os.is_file (name)
Check if a path is a file

Parameters:

Returns:

    boolean is the path a file
os.listdir (dirname)
List the contents of a directory

Parameters:

  • dirname string path of the directory

Returns:

    table sorted table of file names found in dirname
os.path_exists (path)
Check if a path exists

Parameters:

Returns:

    boolean does the path exist
os.path_join (...)
Join one or more paths

Parameters:

  • ... file paths to join

Returns:

    string concatenated path of all names with the correct number of /s
os.read_line (f, n, add_rootDir)
Read a single line from a file

Parameters:

  • f file or string file or filename (see os.read_lines)
  • n number line number to read (starts at 1)
  • add_rootDir bool should rootDir() be prepended to file name

Returns:

    string contents of line at n
os.read_lines (f, add_rootDir)
Read all the lines in a file

Parameters:

  • f file or string file object or file name. If a file object is passed, then it is not closed.
  • add_rootDir bool should rootDir() be prepended to file name

Returns:

    table strings of each line with the newline character removed
os.sizeof (name, add_rootDir)
Get the size of a file or directory

Parameters:

  • name path name to check size of
  • add_rootDir bool should rootDir() be prepended to file name

Returns:

    number size of file/directory at path in bytes
os.sleep (seconds)
Sleep for a certain amount of seconds (millisecond precision)

Parameters:

  • seconds number number of seconds to sleep for
os.write_line (line, n, name, add_rootDir)
Write a single line to a file

Parameters:

  • line string data to write to the file
  • n number line number at which to write the line
  • name string name of file to write to
  • add_rootDir bool should rootDir() be prepended to file name
os.write_lines (lines, name, mode, add_rootDir)
Write multiple lines to a file

Parameters:

  • lines table strings of each line
  • name string name of file to write to
  • mode string write mode (uses same argument as io.open)
  • add_rootDir bool should rootDir() be prepended to file name
generated by LDoc 1.4.6 Last updated 2018-11-10 22:55:04