> ## Documentation Index
> Fetch the complete documentation index at: https://docs.simular.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# File

> Represents a file handle.

## Constructor

```typescript
File(path: string, createMissing: boolean): File
```

Creates a handle to a file at the given path.

If `create_missing` is true, the file (and all missing parent
directories) is created when it does not already exist. If false,
the call fails when the file does not exist.

### Parameters

<ResponseField name={"path"} type={"string"} required />

<ResponseField name={"createMissing"} type={"boolean"} required />

### Returns

`File`

## Methods

### copyTo()

```typescript
copyTo(dest: string): File
```

Copies the file to a new location, returning a handle to the copy.

#### Parameters

<ResponseField name={"dest"} type={"string"} required />

#### Returns

`File`

### delete()

```typescript
delete(): void
```

Deletes the file, invalidating the handle.

### extension()

```typescript
extension(): null | string
```

Returns the file extension, if any.

#### Returns

`null | string`

### isReadonly()

```typescript
isReadonly(): boolean
```

Returns whether the file is read-only.

#### Returns

`boolean`

### modified()

```typescript
modified(): number
```

Returns the last modification time as milliseconds since the Unix
epoch.

#### Returns

`number`

### moveTo()

```typescript
moveTo(dest: string): void
```

Moves the file to a new location.
Falls back to copy + delete for cross-device moves.

#### Parameters

<ResponseField name={"dest"} type={"string"} required />

### name()

```typescript
name(): string
```

Returns the file name (last component of the path).

#### Returns

`string`

### path()

```typescript
path(): string
```

Returns the resolved absolute path.

#### Returns

`string`

### read()

```typescript
read(): string
```

Reads the file and returns its trimmed contents.

#### Returns

`string`

### rename()

```typescript
rename(newName: string): void
```

Renames the file in place (same parent directory).

#### Parameters

<ResponseField name={"newName"} type={"string"} required />

### size()

```typescript
size(): number
```

Returns the file size in bytes.

#### Returns

`number`

### write()

```typescript
write(content: string, append: boolean): void
```

Writes content to the file.

When `append` is true and the file already has content, a newline is
inserted before appending. When `append` is false, the file is
overwritten. Parent directories are created if needed.

#### Parameters

<ResponseField name={"content"} type={"string"} required />

<ResponseField name={"append"} type={"boolean"} required />
