Description
Module to Abstract and provide higher level disk operation functions by using the functionality provided by LuaFileSystemInstallation
There are 2 ways to install it:- The module consists of a single Lua file which can be placed in any path where Lua can find it through its package.path definition.
- Or you can install it using Luarocks by running the command:
Usage
To use the module simply do:Now tu will contain all the functions available for table manipulation
API
Functions
sanitizePath
Function that converts all path separators to '/' and adds one in the end for directories if not already thereSyntax
Usage
Inputs
- path string containing the path
- file boolean to indicate whether the given path points to a file. In that case the ending '/' is not added
Returns
- sanitizedPath string containing the sanitized path
verifyPath
Function to check whether the path existsSyntax
Usage
Inputs
- path string containing the path
Returns
- true is path exists or
- false if path does not exist with message "Path does not exist"
- nil if path is not a string with message "Path should be a string"
recurseIter
Function to return a iterator to traverse the directory and files from the given pathSyntax
Usage
Inputs
- path string containing the path
- fd integer to specify what type of items to list:
- 1 means files only
- 2 means directories only
- anything else means files and directories both
- onlyCurrent boolean when true will only list contents of path directory otherwise it will recurse down
Returns
- iterator table which on every call to iterator.next returns the next item name, its path and its type "file" or "directory"
listLocalHier
Function to list a hierarchy using recurseIter and return it as an arraySyntax
Usage
Inputs
- path string containing the path
- fd integer to specify what type of items to list:
- 1 means files only
- 2 means directories only
- anything else means files and directories both
- onlyCurrent boolean when true will only list contents of path directory otherwise it will recurse down
Returns
- list array containing a 3 element array at each position. The 3 elements are:
- Item name
- Item path
- Item type - "file" or "directory"
emptyDir
Function to empty a directory from all its contentsSyntax
Usage
Inputs
- path string containing the path
Returns
Nothing
getFileName
Function to extract the file name from the pathSyntax
Usage
Inputs
- path string containing the path to the file
Returns
- filename string containing just the file name
createPath
Function to make sure that the given path exists. If not then the full hierarchy is created where required to reach the given path.Syntax
Usage
Inputs
- path string containing the path to create
Returns
- true if successful
- nil and error message if not successful
file_exists
Function to check whether the file exists.Syntax
Usage
Inputs
- file string containing the path and file name to the file to check
Returns
- true if file exists
- false is it does not and the message system returned when trying to open the file.
copyFile
Function to copy a source file to a destination path.Syntax
Usage
Inputs
- source string containing path pointing to file
- destPath string containing path where the file needs to be copied
- fileName string containing name by which the file will be created in destPath with contents of source
- chunkSize integer is the number of bytes read at a time during the copy process
- overwrite boolean if true will overwrite a file with the same name at destPath if it exists
- true if successful
- nil/false with an error message if unsucessful