FileSystemDirectoryHandle.getDirectoryHandle()

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used 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 Standard
# api-filesystemdirectoryhandle-getdirectoryhandle

ブラウザーの互換性

BCD tables only load in the browser

関連情報