Module leste.utils.fs
Provides file system operations such as reading files, executing commands, and listing directory contents.
Functions
system () | Returns the operating system type: "win" for Windows, "unix" for Unix-like systems. |
readFile (filepath, action) | Reads the content of a file. |
exec (commands) | Executes a command and returns its output. |
sep () | Returns the file separator character based on the operating system. |
null () | Null device placeholder for Windows and Unix-like systems. |
path () | Gets the current working directory. |
listDir (path) | Lists the contents of a directory. |
Functions
- system ()
-
Returns the operating system type: "win" for Windows, "unix" for Unix-like systems.
Returns:
-
string
The operating system type.
- readFile (filepath, action)
-
Reads the content of a file.
Parameters:
- filepath string The path to the file to read.
- action function Optional. The function to open the file. Defaults to io.open.
Returns:
-
string
The content of the file.
- exec (commands)
-
Executes a command and returns its output.
Parameters:
- commands table A table with "win" and "unix" keys specifying the commands to execute on each OS.
Returns:
-
string
The output of the executed command.
- sep ()
-
Returns the file separator character based on the operating system.
Returns:
-
string
The file separator character.
- null ()
-
Null device placeholder for Windows and Unix-like systems.
Returns:
-
string
The null device location.
- path ()
-
Gets the current working directory.
Returns:
-
string
The current working directory.
- listDir (path)
-
Lists the contents of a directory.
Parameters:
- path string Optional. The path to the directory. Defaults to the current working directory.
Returns:
-
table
A table of filenames in the directory.