FileSystemDirectoryHandle.getDirectoryHandle()

Baseline 2023
Newly available

Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。

FileSystemDirectoryHandle インターフェイスの getDirectoryHandle() メソッドは、このメソッドが呼ばれたディレクトリーハンドル内の指定した名前のサブディレクトリーを表す FileSystemDirectoryHandle を返します。

構文

js
getDirectoryHandle(name)
getDirectoryHandle(name, options)

引数

name

取得したいサブディレクトリーの FileSystemHandle.name を表す文字列です。

options 省略可

取得するサブディレクトリーに関するオプションを持つオブジェクトで、省略可能です。以下のオプションがあります。

create

boolean 値で、デフォルトは false です。true に設定すると、ディレクトリーが見つからない場合、指定した名前のディレクトリーが作成されて返されます。

返値

FileSystemDirectoryHandle で解決する Promise を返します。

例外

NotAllowedError DOMException

PermissionStatus'granted' でないとき投げられます。

TypeMismatchError DOMException

返されるエントリーがファイルで、ディレクトリーではないとき投げられます。

NotFoundError DOMException

ディレクトリーが存在せず、create オプションが false に設定されているとき投げられます。

以下の例では、指定した名前のディレクトリーハンドルを返します。ディレクトリーが存在しない場合、作成されます。

js
const dirName = "directoryToGetName";

// ディレクトリーハンドル 'currentDirHandle' があると仮定
const subDir = currentDirHandle.getDirectoryHandle(dirName, { create: true });

仕様書

Specification
File System
# api-filesystemdirectoryhandle-getdirectoryhandle

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
getDirectoryHandle

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

関連情報