2022-12-15 04:00:54 +00:00
|
|
|
---
|
|
|
|
title: Module fs
|
|
|
|
description: filesystem interaction and functionality library
|
|
|
|
layout: doc
|
|
|
|
menu:
|
|
|
|
docs:
|
|
|
|
parent: "API"
|
|
|
|
---
|
|
|
|
|
|
|
|
## Introduction
|
|
|
|
The fs module provides easy and simple access to filesystem functions
|
|
|
|
and other things, and acts an addition to the Lua standard library's
|
|
|
|
I/O and filesystem functions.
|
|
|
|
|
|
|
|
## Functions
|
2023-09-02 18:18:40 +00:00
|
|
|
|||
|
|
|
|
|----|----|
|
|
|
|
|<a href="#abs">abs(path) -> string</a>|Gives an absolute version of `path`.|
|
|
|
|
|<a href="#basename">basename(path) -> string</a>|Gives the basename of `path`. For the rules,|
|
|
|
|
|<a href="#cd">cd(dir)</a>|Changes directory to `dir`|
|
|
|
|
|<a href="#dir">dir(path) -> string</a>|Returns the directory part of `path`. For the rules, see Go's|
|
|
|
|
|<a href="#glob">glob(pattern) -> matches (table)</a>|Glob all files and directories that match the pattern.|
|
|
|
|
|<a href="#join">join(...) -> string</a>|Takes paths and joins them together with the OS's|
|
|
|
|
|<a href="#mkdir">mkdir(name, recursive)</a>|Makes a directory called `name`. If `recursive` is true, it will create its parent directories.|
|
|
|
|
|<a href="#readdir">readdir(dir) -> {}</a>|Returns a table of files in `dir`.|
|
|
|
|
|<a href="#stat">stat(path) -> {}</a>|Returns a table of info about the `path`.|
|
|
|
|
|
|
|
|
<hr><div id='abs'>
|
|
|
|
<h4 class='heading'>
|
|
|
|
fs.abs(path) -> string
|
|
|
|
<a href="#abs" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
Gives an absolute version of `path`.
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
|
|
|
This function has no parameters.
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr><div id='basename'>
|
2023-09-02 18:18:40 +00:00
|
|
|
<h4 class='heading'>
|
|
|
|
fs.basename(path) -> string
|
|
|
|
<a href="#basename" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
2022-12-15 04:00:54 +00:00
|
|
|
|
|
|
|
Gives the basename of `path`. For the rules,
|
|
|
|
see Go's filepath.Base
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
|
|
|
This function has no parameters.
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr><div id='cd'>
|
2023-09-02 18:18:40 +00:00
|
|
|
<h4 class='heading'>
|
|
|
|
fs.cd(dir)
|
|
|
|
<a href="#cd" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
2022-12-15 04:00:54 +00:00
|
|
|
|
|
|
|
Changes directory to `dir`
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
|
|
|
This function has no parameters.
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr><div id='dir'>
|
2023-09-02 18:18:40 +00:00
|
|
|
<h4 class='heading'>
|
|
|
|
fs.dir(path) -> string
|
|
|
|
<a href="#dir" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
2022-12-15 04:00:54 +00:00
|
|
|
|
|
|
|
Returns the directory part of `path`. For the rules, see Go's
|
|
|
|
filepath.Dir
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
|
|
|
This function has no parameters.
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr><div id='glob'>
|
2023-09-02 18:18:40 +00:00
|
|
|
<h4 class='heading'>
|
|
|
|
fs.glob(pattern) -> matches (table)
|
|
|
|
<a href="#glob" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
2022-12-15 04:00:54 +00:00
|
|
|
|
|
|
|
Glob all files and directories that match the pattern.
|
|
|
|
For the rules, see Go's filepath.Glob
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
|
|
|
This function has no parameters.
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr><div id='join'>
|
2023-09-02 18:18:40 +00:00
|
|
|
<h4 class='heading'>
|
|
|
|
fs.join(...) -> string
|
|
|
|
<a href="#join" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
2022-12-15 04:00:54 +00:00
|
|
|
|
|
|
|
Takes paths and joins them together with the OS's
|
|
|
|
directory separator (forward or backward slash).
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
|
|
|
This function has no parameters.
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr><div id='mkdir'>
|
2023-09-02 18:18:40 +00:00
|
|
|
<h4 class='heading'>
|
|
|
|
fs.mkdir(name, recursive)
|
|
|
|
<a href="#mkdir" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
2022-12-15 04:00:54 +00:00
|
|
|
|
|
|
|
Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
|
|
|
This function has no parameters.
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr><div id='readdir'>
|
2023-09-02 18:18:40 +00:00
|
|
|
<h4 class='heading'>
|
|
|
|
fs.readdir(dir) -> {}
|
|
|
|
<a href="#readdir" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
2022-12-15 04:00:54 +00:00
|
|
|
|
2022-12-21 00:59:55 +00:00
|
|
|
Returns a table of files in `dir`.
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
|
|
|
This function has no parameters.
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr><div id='stat'>
|
2023-09-02 18:18:40 +00:00
|
|
|
<h4 class='heading'>
|
|
|
|
fs.stat(path) -> {}
|
|
|
|
<a href="#stat" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
2022-12-15 04:00:54 +00:00
|
|
|
|
2022-12-21 00:59:55 +00:00
|
|
|
Returns a table of info about the `path`.
|
|
|
|
It contains the following keys:
|
|
|
|
name (string) - Name of the path
|
|
|
|
size (number) - Size of the path
|
|
|
|
mode (string) - Permission mode in an octal format string (with leading 0)
|
|
|
|
isDir (boolean) - If the path is a directory
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
|
|
|
This function has no parameters.
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|