> For the complete documentation index, see [llms.txt](https://lua2.axeprimecs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lua2.axeprimecs.com/global-functions/global-functions/network/filesystem.md).

# Filesystem

File system operations. Write/remove operations require the **File Access** permission.

***

## Functions

| Function                      | Parameters         | Returns  | Description                  |
| ----------------------------- | ------------------ | -------- | ---------------------------- |
| `fs.read(path)`               | `string`           | `string` | Read entire file as string   |
| `fs.read_stream(path)`        | `string`           | `table`  | Read file as byte array      |
| `fs.write(path, data)`        | `string`, `string` |          | Write string to file         |
| `fs.write_stream(path, data)` | `string`, `table`  |          | Write byte array to file     |
| `fs.remove(path)`             | `string`           |          | Delete a file                |
| `fs.exists(path)`             | `string`           | `bool`   | Check if path exists         |
| `fs.is_file(path)`            | `string`           | `bool`   | Check if path is a file      |
| `fs.is_dir(path)`             | `string`           | `bool`   | Check if path is a directory |
| `fs.create_dir(path)`         | `string`           |          | Create directory (recursive) |

***

## 💡 Example

```lua
fs.write("output.txt", "Hello from Lua!")
local content = fs.read("output.txt")
print(content)

if fs.exists("config.json") then
    local data = fs.read("config.json")
end
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://lua2.axeprimecs.com/global-functions/global-functions/network/filesystem.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
