---
name: FileSystemService
last_updated: 2026-11-20T18:47:25Z
inherits:
  - Instance
  - Object
type: class
memory_category: Instances
summary: "Provides sandboxed access to the local file system for Luau scripts run through the Roblox command-line environment."
---

# Class: FileSystemService

> Provides sandboxed access to the local file system for Luau scripts run
> through the Roblox command-line environment.

## Description

[FileSystemService](/docs/reference/engine/classes/FileSystemService.md) exposes file and directory operations — reading,
writing, existence checks, traversal, and removal — to Luau code executing in
Roblox's command-line (CLI) toolchain.

Every path is first resolved to a canonical, generic (forward-slash) form, and
each operation is checked against a sandbox that restricts which locations a
script may access. An operation whose target resolves outside the sandbox
raises an error rather than touching the file system. Read-only operations
such as [Exists()](/docs/reference/engine/classes/FileSystemService.md) and
[ReadFile()](/docs/reference/engine/classes/FileSystemService.md) require read access to the
path, while mutating operations such as
[WriteFile()](/docs/reference/engine/classes/FileSystemService.md),
[Remove()](/docs/reference/engine/classes/FileSystemService.md),
[RemoveAll()](/docs/reference/engine/classes/FileSystemService.md), and
[CreateDirectories()](/docs/reference/engine/classes/FileSystemService.md) require
read-write access.

## Methods

### Method: FileSystemService:CreateDirectories

**Signature:** `FileSystemService:CreateDirectories(folderPath: string): ()`

Creates the directory named by `folderPath`, also creating any
intermediate parent directories that do not already exist. `folderPath`
must resolve to a location the script is permitted to write to; a path
outside the sandbox raises an error.

*Security: None · Thread Safety: Unsafe*

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `folderPath` | `string` |  | The path of the directory to create. |

**Returns:** `()`

### Method: FileSystemService:Exists

**Signature:** `FileSystemService:Exists(filePath: string): boolean`

Returns `true` when a file or directory exists at `filePath` and `false`
when nothing exists there. Requires read access to the path; a path that
resolves outside the sandbox raises an error rather than returning
`false`.

*Security: None · Thread Safety: Unsafe*

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `filePath` | `string` |  | The path to test. |

**Returns:** `boolean` — `true` if a file or directory exists at `filePath`, otherwise `false`.

### Method: FileSystemService:IsDirectory

**Signature:** `FileSystemService:IsDirectory(filePath: string): boolean`

Returns `true` when `filePath` exists and is a directory. Returns `false`
for regular files and for paths that do not exist. Requires read access; a
path that resolves outside the sandbox raises an error.

*Security: None · Thread Safety: Unsafe*

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `filePath` | `string` |  | The path to test. |

**Returns:** `boolean` — `true` if `filePath` refers to an existing directory, otherwise
`false`.

### Method: FileSystemService:IsRegularFile

**Signature:** `FileSystemService:IsRegularFile(filePath: string): boolean`

Returns `true` when `filePath` exists and is a regular file. Returns
`false` for directories and for paths that do not exist. Requires read
access; a path that resolves outside the sandbox raises an error.

*Security: None · Thread Safety: Unsafe*

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `filePath` | `string` |  | The path to test. |

**Returns:** `boolean` — `true` if `filePath` refers to an existing regular file, otherwise
`false`.

### Method: FileSystemService:ReadFile

**Signature:** `FileSystemService:ReadFile(filePath: string, mode: FileMode): string`

Reads the file at `filePath` and returns its contents as a string. When
`mode` is [FileMode.Text](/docs/reference/engine/enums/FileMode.md) (the default), carriage-return/line-feed
pairs (`\r\n`) are normalized to line feeds (`\n`); when `mode` is
[FileMode.Binary](/docs/reference/engine/enums/FileMode.md), the bytes are returned unmodified. Requires read
access; a path that resolves outside the sandbox raises an error.

*Security: None · Thread Safety: Unsafe*

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `filePath` | `string` |  | The path of the file to read. |
| `mode` | `FileMode` |  | Whether to read the file as text or binary. Defaults to [FileMode.Text](/docs/reference/engine/enums/FileMode.md). |

**Returns:** `string` — The contents of the file at `filePath` as a string.

### Method: FileSystemService:Remove

**Signature:** `FileSystemService:Remove(filePath: string): ()`

Removes the file or empty directory at `filePath`. To delete a directory
together with everything it contains, use
[RemoveAll()](/docs/reference/engine/classes/FileSystemService.md) instead. Requires
read-write access; a path that resolves outside the sandbox raises an
error.

*Security: None · Thread Safety: Unsafe*

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `filePath` | `string` |  | The path of the file or empty directory to remove. |

**Returns:** `()`

### Method: FileSystemService:RemoveAll

**Signature:** `FileSystemService:RemoveAll(filePath: string): ()`

Removes `filePath` and, when it is a directory, everything it contains,
recursively. Use [Remove()](/docs/reference/engine/classes/FileSystemService.md) instead when
you only need to delete a single file or an empty directory. Requires
read-write access; a path that resolves outside the sandbox raises an
error.

*Security: None · Thread Safety: Unsafe*

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `filePath` | `string` |  | The path of the file or directory to remove. |

**Returns:** `()`

### Method: FileSystemService:Walk

**Signature:** `FileSystemService:Walk(folderPath: string, mode: FileSystemWalkMode): ()`

Returns an iterator function, suitable for a generic `for` loop, that
visits the entries contained in `folderPath`. Each iteration produces a
table with `Path`, `IsRegularFile`, and `Depth` fields.

When `mode` is [FileSystemWalkMode.Recursive](/docs/reference/engine/enums/FileSystemWalkMode.md), the iterator descends
into subdirectories, incrementing `Depth` for each level below
`folderPath`. When `mode` is [FileSystemWalkMode.NonRecursive](/docs/reference/engine/enums/FileSystemWalkMode.md) — the
behavior used when `mode` is omitted — only the immediate entries of
`folderPath` are visited, each reported at `Depth` `1`.

Requires read access; a path that resolves outside the sandbox raises an
error.

```lua
for entry in fs:Walk(folderPath, Enum.FileSystemWalkMode.Recursive) do
	print(entry.Path, entry.IsRegularFile, entry.Depth)
end
```

*Security: None · Thread Safety: Unsafe*

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `folderPath` | `string` |  | The path of the directory to traverse. |
| `mode` | `FileSystemWalkMode` |  | Whether to descend into subdirectories. When omitted, traversal is non-recursive. |

**Returns:** `()` — An iterator function for use in a generic `for` loop. Each step yields
a table describing one entry, with fields `Path` (the entry's path),
`IsRegularFile` (whether the entry is a regular file), and `Depth`
(the entry's depth relative to `folderPath`, starting at `1`).

### Method: FileSystemService:WriteFile

**Signature:** `FileSystemService:WriteFile(filePath: string, content: string, mode: FileMode): ()`

Writes `content` to the file at `filePath`, creating the file if it does
not exist and overwriting it if it does. When `mode` is
[FileMode.Text](/docs/reference/engine/enums/FileMode.md) (the default), carriage-return/line-feed pairs
(`\r\n`) in `content` are normalized to line feeds (`\n`); when `mode` is
[FileMode.Binary](/docs/reference/engine/enums/FileMode.md), the content is written unmodified. Requires
read-write access; a path that resolves outside the sandbox raises an
error.

*Security: None · Thread Safety: Unsafe*

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `filePath` | `string` |  | The path of the file to write. |
| `content` | `string` |  | The string contents to write to the file. |
| `mode` | `FileMode` |  | Whether to write the content as text or binary. Defaults to [FileMode.Text](/docs/reference/engine/enums/FileMode.md). |

**Returns:** `()`

## Inherited Members

### From [Instance](/docs/reference/engine/classes/Instance.md)

- **Property `Archivable`** (`boolean`): Determines if an Instance and its descendants can be cloned using
- **Property `archivable`** (`boolean`):  *(deprecated, hidden)*
- **Property `Capabilities`** (`SecurityCapabilities`): The set of capabilities allowed to be used for scripts inside this
- **Property `IsInSandbox`** (`boolean`): Indicates whether the instance is inside a sandboxed container.
- **Property `Name`** (`string`): A non-unique identifier of the Instance.
- **Property `Parent`** (`Instance`): Determines the hierarchical parent of the Instance.
- **Property `PredictionMode`** (`PredictionMode`): Reflects the client-side prediction mode applied to the instance under
- **Property `RobloxLocked`** (`boolean`): A deprecated property that used to protect CoreGui objects. *(hidden)*
- **Property `Sandboxed`** (`boolean`): When enabled, the instance can only access abilities in its `Capabilities`
- **Property `UniqueId`** (`UniqueId`): A unique identifier for the instance.
- **Method `AddTag(tag: string): ()`**: Applies a tag to the instance.
- **Method `children(): Instances`**: Returns an array of the object's children. *(deprecated)*
- **Method `ClearAllChildren(): ()`**: This method destroys all of an instance's children.
- **Method `Clone(): Instance`**: Create a copy of an instance and all its descendants, ignoring instances
- **Method `clone(): Instance`**:  *(deprecated)*
- **Method `Destroy(): ()`**: Sets the Instance.Parent property to `nil`, locks the
- **Method `destroy(): ()`**:  *(deprecated)*
- **Method `FindFirstAncestor(name: string): Instance?`**: Returns the first ancestor of the Instance whose
- **Method `FindFirstAncestorOfClass(className: string): Instance?`**: Returns the first ancestor of the Instance whose
- **Method `FindFirstAncestorWhichIsA(className: string): Instance?`**: Returns the first ancestor of the Instance for whom
- **Method `FindFirstChild(name: string, recursive?: boolean): Instance?`**: Returns the first child of the Instance found with the given name.
- **Method `findFirstChild(name: string, recursive?: boolean): Instance`**:  *(deprecated)*
- **Method `FindFirstChildOfClass(className: string): Instance?`**: Returns the first child of the Instance whose
- **Method `FindFirstChildWhichIsA(className: string, recursive?: boolean): Instance?`**: Returns the first child of the Instance for whom
- **Method `FindFirstDescendant(name: string): Instance?`**: Returns the first descendant found with the given Instance.Name.
- **Method `GetActor(): Actor?`**: Returns the Actor associated with the Instance, if any.
- **Method `GetAttribute(attribute: string): Variant`**: Returns the value which has been assigned to the given attribute name.
- **Method `GetAttributeChangedSignal(attribute: string): RBXScriptSignal`**: Returns an event that fires when the given attribute changes.
- **Method `GetAttributes(): Dictionary`**: Returns a dictionary of the instance's attributes.
- **Method `GetChildren(): Instances`**: Returns an array containing all of the instance's children.
- **Method `getChildren(): Instances`**:  *(deprecated)*
- **Method `GetDebugId(scopeLength?: int): string`**: Returns a coded string of the debug ID used internally by Roblox.
- **Method `GetDescendants(): Instances`**: Returns an array containing all of the descendants of the instance.
- **Method `GetFullName(): string`**: Returns a string describing the instance's ancestry.
- **Method `GetStyled(name: string, selector: string?): Variant`**: Returns the styled or explicitly modified value of the specified property,
- **Method `GetStyledPropertyChangedSignal(property: string): RBXScriptSignal`**: Returns an event that fires when the given style property changes on the
- **Method `GetTags(): Array`**: Gets an array of all tags applied to the instance.
- **Method `HasTag(tag: string): boolean`**: Check whether the instance has a given tag.
- **Method `IsAncestorOf(descendant: Instance): boolean`**: Returns true if an Instance is an ancestor of the given
- **Method `IsDescendantOf(ancestor: Instance): boolean`**: Returns `true` if an Instance is a descendant of the given
- **Method `isDescendantOf(ancestor: Instance): boolean`**:  *(deprecated)*
- **Method `IsPropertyModified(property: string): boolean`**: Returns `true` if the value stored in the specified property is not equal
- **Method `QueryDescendants(selector: string): Instances`**: Returns an array containing all descendants of the instance that match the
- **Method `Remove(): ()`**: Sets the object's `Parent` to `nil`, and does the same for all its *(deprecated)*
- **Method `remove(): ()`**:  *(deprecated)*
- **Method `RemoveTag(tag: string): ()`**: Removes a tag from the instance.
- **Method `ResetPropertyToDefault(property: string): ()`**: Resets a property to its default value.
- **Method `SetAttribute(attribute: string, value: Variant): ()`**: Sets the attribute with the given name to the given value.
- **Method `WaitForChild(childName: string, timeOut: double): Instance`**: Returns the child of the Instance with the given name. If the
- **Event `AncestryChanged`**: Fires when the Instance.Parent property of this object or one of
- **Event `AttributeChanged`**: Fires whenever an attribute is changed on the Instance.
- **Event `ChildAdded`**: Fires after an object is parented to this Instance.
- **Event `childAdded`**:  *(deprecated)*
- **Event `ChildRemoved`**: Fires after a child is removed from this Instance.
- **Event `DescendantAdded`**: Fires after a descendant is added to the Instance.
- **Event `DescendantRemoving`**: Fires immediately before a descendant of the Instance is removed.
- **Event `Destroying`**: Fires immediately before (or is deferred until after) the instance is
- **Event `StyledPropertiesChanged`**: Fires whenever any style property is changed on the instance, including

### From [Object](/docs/reference/engine/classes/Object.md)

- **Property `ClassName`** (`string`): A read-only string representing the class this Object belongs to.
- **Property `className`** (`string`):  *(deprecated)*
- **Method `GetPropertyChangedSignal(property: string): RBXScriptSignal`**: Get an event that fires when a given property of the object changes.
- **Method `IsA(className: string): boolean`**: Returns true if an object's class matches or inherits from a given class.
- **Method `isA(className: string): boolean`**:  *(deprecated)*
- **Event `Changed`**: Fires immediately after a property of the object changes, with some