# File

**File:**

All file operations are sandboxed to `C:\Yerb\V3\Luas\` and have a 10MB size limit. Dangerous file types and system paths are blocked.

`File.Read(path)`: Returns the full contents of the file at `path` as a string. Returns an empty string if the file doesn't exist or is blocked.

```lua
local content = File.Read("C:\\Yerb\\V3\\Luas\\config.txt")
print(content)
```

`File.Write(path, content)`: Writes `content` to the file at `path`, overwriting it. Returns `true` on success.

```lua
File.Write("C:\\Yerb\\V3\\Luas\\config.txt", "hello world")
```

`File.Exists(path)`: Returns `true` if the file or directory at `path` exists.

```lua
if File.Exists("C:\\Yerb\\V3\\Luas\\config.txt") then
    print("found")
end
```

`File.CreateDirectory(path)`: Creates the directory (and any missing parents) at `path`. Returns `true` on success.

```lua
File.CreateDirectory("C:\\Yerb\\V3\\Luas\\mymod")
```

`File.Append(path, content)`: Appends `content` to the end of the file at `path`. Returns `true` on success.

```lua
File.Append("C:\\Yerb\\V3\\Luas\\log.txt", "new line\n")
```

`File.Delete(path)`: Deletes the file at `path`. Returns `true` on success. Directories cannot be deleted.

```lua
File.Delete("C:\\Yerb\\V3\\Luas\\old.txt")
```

`File.List(path)`: Returns a table of filenames inside the given directory.

```lua
local files = File.List("C:\\Yerb\\V3\\Luas\\")
for _, name in ipairs(files) do
    print(name)
end
```

`File.ReadBytes(path)`: Reads the file as raw binary and returns a table of integers (0–255), one per byte.

```lua
local bytes = File.ReadBytes("C:\\Yerb\\V3\\Luas\\data.bin")
print(bytes[1])
```

`File.WriteBytes(path, bytes)`: Writes a table of integers (0–255) as raw binary to the file.

```lua
File.WriteBytes("C:\\Yerb\\V3\\Luas\\data.bin", {72, 101, 108, 108, 111})
```

`File.Rename(from, to)`: Renames or moves a file within the sandbox. Returns `true` on success.

```lua
File.Rename("C:\\Yerb\\V3\\Luas\\old.txt", "C:\\Yerb\\V3\\Luas\\new.txt")
```

`File.FileSize(path)`: Returns the size of the file in bytes, or `-1` on error.

```lua
local sz = File.FileSize("C:\\Yerb\\V3\\Luas\\config.txt")
print(sz)
```


---

# Agent Instructions: 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:

```
GET https://yerba-1.gitbook.io/yerba-docs/api/file.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
