このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

FileSystemDirectoryHandle.getDirectoryHandle()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2023年3月⁩.

安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (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

ブラウザーの互換性

関連情報