# Window: showDirectoryPicker() method



The **`showDirectoryPicker()`** method of the
[Window](https://developer.mozilla.org/en-US/docs/Web/API/Window) interface displays a directory picker which allows the user to
select a directory.

## Syntax

```js-nolint
showDirectoryPicker()
showDirectoryPicker(options)
```

### Parameters

- `options` 
  - : An object containing options, which are as follows:
    - `id` 
      - : By specifying an ID, the browser can remember different directories for different
        IDs. If the same ID is used for another picker, the picker opens in the same
        directory.
    - `mode` 
      - : A string that defaults to `"read"` for read-only access or `"readwrite"` for read
        and write access to the directory.
    - `startIn` 
      - : A [FileSystemHandle](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle) or a well-known directory (`"desktop"`, `"documents"`,
        `"downloads"`, `"music"`, `"pictures"`, or `"videos"`) to open the dialog in.

### Return value

A [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) whose fulfillment handler receives a [FileSystemDirectoryHandle](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle) object.

### Exceptions

- `AbortError` [DOMException](https://developer.mozilla.org/en-US/docs/Web/API/DOMException)
  - : Thrown if the user dismisses the prompt without making a selection,
    or if the user agent deems the selected directory to be too sensitive or dangerous,
    or if the [PermissionStatus.state](https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus/state) for the selected directory is not `"granted"` in the specified `mode`.
- `SecurityError` [DOMException](https://developer.mozilla.org/en-US/docs/Web/API/DOMException)
  - : Thrown if the call was blocked by the [same-origin policy](https://developer.mozilla.org/en-US/docs/Web/Security/Defenses/Same-origin_policy) or it was not called via a user interaction such as a button press.

## Security

[Transient user activation](https://developer.mozilla.org/en-US/docs/Web/Security/Defenses/User_activation) is required. The user has to interact with the page or a UI element in order for this feature to work.

## Examples

This asynchronous function shows a directory picker and returns a
[FileSystemDirectoryHandle](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle) once selected.

```js
async function getDir() {
  const dirHandle = await window.showDirectoryPicker();

  // run code for dirHandle
}
```

## Specifications

## Browser compatibility

## See also

- [File System API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API)
- [The File System Access API: simplifying access to local files](https://developer.chrome.com/docs/capabilities/web-apis/file-system-access)
