# std.fs

Filesystem operations for reading, writing, and managing files and directories.

```tea
use fs from "std.fs"
```

Examples may be fragments requiring the module import or additional setup.

## std.fs.read_file

```tea
pub def read_file(file_path: String) -> String ! FsError
```

Read a text file.

```tea
var content = fs.read_file("file.txt")
```

## std.fs.read_bytes

```tea
pub def read_bytes(file_path: String) -> List[Int] ! FsError
```

Read a file as raw bytes.

```tea
use fs from "std.fs"

const file = fs.create_temp_file("tea-bytes-")
fs.write_bytes(file, [0, 127, 255])
@println(fs.read_bytes(file)) # [0, 127, 255]
fs.remove(file)
```

## std.fs.write_file

```tea
pub def write_file(file_path: String, content: String) -> Void ! FsError
```

Write text to a file.

```tea
fs.write_file("file.txt", "Hello, world!")
```

## std.fs.write_file_atomic

```tea
pub def write_file_atomic(file_path: String, content: String) -> Void ! FsError
```

Write text to a file atomically.

```tea
use fs from "std.fs"

const file = fs.create_temp_file("tea-config-")
fs.write_file_atomic(file, "theme=dark\n")
@println(fs.read_file(file))
fs.remove(file)
```

## std.fs.write_bytes

```tea
pub def write_bytes(file_path: String, data: List[Int]) -> Void ! FsError
```

Write raw bytes to a file.

## std.fs.write_bytes_atomic

```tea
pub def write_bytes_atomic(file_path: String, data: List[Int]) -> Void ! FsError
```

Write raw bytes to a file atomically.

```tea
use fs from "std.fs"

const file = fs.create_temp_file("tea-bytes-")
fs.write_bytes_atomic(file, [0, 127, 255])
@println(fs.read_bytes(file)) # [0, 127, 255]
fs.remove(file)
```

## std.fs.create_dir

```tea
pub def create_dir(dir_path: String) -> Void ! FsError
```

Create a directory.

```tea
fs.create_dir("my_dir")
```

## std.fs.ensure_dir

```tea
pub def ensure_dir(dir_path: String) -> Void ! FsError
```

Create a directory and any missing parent directories.

## std.fs.ensure_parent

```tea
pub def ensure_parent(file_path: String) -> Void ! FsError
```

Create any missing parent directories for a file path.

```tea
use fs from "std.fs"
use path from "std.path"

const directory = fs.create_temp_dir("tea-output-")
const file = path.join([directory, "reports", "summary.txt"])
fs.ensure_parent(file)
fs.write_file(file, "All checks passed")
@println(fs.exists(file)) # true
fs.remove(directory)
```

## std.fs.mkdir_p

```tea
pub def mkdir_p(dir_path: String) -> Void ! FsError
```

Alias for ensure_dir().

## std.fs.remove

```tea
pub def remove(file_path: String) -> Void ! FsError
```

Remove a file or directory.

```tea
fs.remove("file.txt")
```

## std.fs.exists

```tea
pub def exists(file_path: String) -> Bool ! FsError
```

Return true when a path exists.

## std.fs.is_symlink

```tea
pub def is_symlink(file_path: String) -> Bool ! FsError
```

Return true when the path is a symbolic link.

## std.fs.read_symlink

```tea
pub def read_symlink(file_path: String) -> String ! FsError
```

Return the target path stored in a symbolic link.

## std.fs.create_file_symlink

```tea
pub def create_file_symlink(target_path: String, link_path: String) -> Void ! FsError
```

Create a symbolic link that points at a file target.

## std.fs.create_dir_symlink

```tea
pub def create_dir_symlink(target_path: String, link_path: String) -> Void ! FsError
```

Create a symbolic link that points at a directory target.

## std.fs.read_dir

```tea
pub def read_dir(dir_path: String) -> List[String] ! FsError
```

List all entries in a directory.

```tea
var entries = fs.read_dir(".")
```

## std.fs.walk

```tea
pub def walk(dir_path: String) -> List[String] ! FsError
```

Recursively walk a directory and return full entry paths.

## std.fs.glob

```tea
pub def glob(pattern: String) -> List[String] ! FsError
```

Return filesystem entries that match a glob pattern.

## std.fs.copy

```tea
pub def copy(source_path: String, target_path: String) -> Void ! FsError
```

Copy a file to a new location.

## std.fs.rename

```tea
pub def rename(source_path: String, target_path: String) -> Void ! FsError
```

Rename or move a file or directory.

## std.fs.metadata

```tea
pub def metadata(file_path: String) -> FileMetadata ! FsError
```

Get metadata information for a file or directory.

## std.fs.stat

```tea
pub def stat(file_path: String) -> FileMetadata ! FsError
```

Alias for metadata().

## std.fs.read_lines

```tea
pub def read_lines(file_path: String) -> List[String] ! FsError
```

Read a text file and split it into lines.

```tea
use fs from "std.fs"

const file = fs.create_temp_file("tea-lines-")
fs.write_lines(file, ["tea", "coffee"])
for line in fs.read_lines(file)
  @println(line)
end
fs.remove(file)
```

## std.fs.write_lines

```tea
pub def write_lines(file_path: String, lines: List[String]) -> Void ! FsError
```

Write a list of lines to a file, joining them with "\n".

## std.fs.append_bytes

```tea
pub def append_bytes(file_path: String, data: List[Int]) -> Void ! FsError
```

Append raw bytes to a file, creating it when it does not exist.

## std.fs.append_file

```tea
pub def append_file(file_path: String, content: String) -> Void ! FsError
```

Append text to a file, creating it when it does not exist.

## std.fs.create_temp_dir

```tea
pub def create_temp_dir(prefix: String) -> String ! FsError
```

Create a unique temporary directory and return its path.

```tea
use fs from "std.fs"

const directory = fs.create_temp_dir("tea-example-")
@println(fs.exists(directory)) # true
fs.remove(directory)
```

## std.fs.create_temp_file

```tea
pub def create_temp_file(prefix: String) -> String ! FsError
```

Create a unique temporary file and return its path.

```tea
use fs from "std.fs"

const file = fs.create_temp_file("tea-example-")
fs.write_file(file, "Hello, Tea!")
@println(fs.read_file(file)) # Hello, Tea!
fs.remove(file)
```
