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

# Directory picker

> Let users pick a folder with the native directory dialog

[See the platform support matrix](https://filekit.mintlify.site/platform-support.md#filekit-dialogs)

`openDirectoryPicker` shows the platform's native folder dialog and returns the selected folder as a `PlatformFile`.

## Usage

```kotlin Compose theme={null}
val launcher = rememberDirectoryPickerLauncher(
    onError = { failure -> showError(failure.message) },
) { directory ->
    // directory is a PlatformFile, or null when the user cancelled
}

Button(onClick = { launcher.launch() }) {
    Text("Pick a folder")
}
```

```kotlin Suspend API theme={null}
val directory: PlatformFile? = FileKit.openDirectoryPicker()
```

The result is `null` when the user cancels. Failures go to `onError` in Compose, or are thrown as a `FileKitDialogException` by the suspend API. See [Results and errors](https://filekit.mintlify.site/dialogs/error-handling.md).

## Try it

This is the FileKit sample running in your browser. Pick a folder to browse its contents as a tree, then open a file to inspect its metadata.

[Open in a new tab ↗](https://vinceglb.github.io/FileKit/?demo=directory-picker)

## Options

In Compose, pass these options to `rememberDirectoryPickerLauncher`. `launch()` takes no arguments.

**directory** `PlatformFile?` (default: null)

Folder the dialog opens in. Ignored on the web.

**dialogSettings** `FileKitDialogSettings` (default: createDefault())

Title, parent window, and other [per-platform settings](https://filekit.mintlify.site/dialogs/dialog-settings.md).

## Read the folder's contents

Call `list()` for the direct children or `walk()` for the whole tree. See [File operations](https://filekit.mintlify.site/core/file-operations.md#list-a-directory).

## Keep access across launches

A picked folder is only accessible for the current session on Android and Apple platforms. Save its bookmark to reopen it after a restart:

```kotlin nonWebMain theme={null}
val directory = FileKit.openDirectoryPicker() ?: return
val bookmark = directory.bookmarkData()
saveBytes("project_folder", bookmark.bytes)

// After a restart
val restored = PlatformFile.fromBookmarkData(loadBytes("project_folder"))
```

`saveBytes` and `loadBytes` stand for your own storage. See [Bookmark data](https://filekit.mintlify.site/core/bookmark-data.md) for invalid bookmarks and security-scoped access on Apple platforms.

## Platform notes

| Platform | Behavior |
| - | - |
| Android | Storage Access Framework tree picker. The result is a `content://` tree URI. |
| iOS | `UIDocumentPickerViewController` in folder mode. |
| macOS | `NSOpenPanel` configured for folders. |
| JVM | Native dialog on macOS and Windows, and the XDG Desktop Portal on Linux with a Swing fallback when no portal runs. |
| Linux native | XDG Desktop Portal only, with no fallback dialog. See [Linux setup](https://filekit.mintlify.site/dialogs/setup.md#linux-setup). |
| Windows native | `IFileDialog` in folder mode. |
| Web | Browsers expose the folder as a flat file list, so FileKit rebuilds a read-only tree from relative paths. Empty subfolders are missing, folders report a `lastModified()` of epoch `0`, and an empty folder returns `null`, like a cancellation. |

## Related

* [Bookmark data](https://filekit.mintlify.site/core/bookmark-data.md) to keep access to the folder.
* [Results and errors](https://filekit.mintlify.site/dialogs/error-handling.md) for cancellation and failure handling.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.