FileSystemDirectoryHandle.getDirectoryHandle()
Baseline
広く利用可能
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2023年3月以降、すべてのブラウザーで利用可能です。
安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。
FileSystemDirectoryHandle インターフェイスの getDirectoryHandle() メソッドは、このメソッドが呼ばれたディレクトリーハンドル内の指定した名前のサブディレクトリーを表す FileSystemDirectoryHandle を返します。
構文
js
getDirectoryHandle(name)
getDirectoryHandle(name, options)
引数
name-
取得したいサブディレクトリーの
FileSystemHandle.nameを表す文字列です。 options省略可-
取得するサブディレクトリーに関するオプションを持つオブジェクトで、省略可能です。以下のオプションがあります。
返値
FileSystemDirectoryHandle で解決する Promise を返します。
例外
NotAllowedErrorDOMException-
PermissionStatusが'granted'でないとき投げられます。 TypeMismatchErrorDOMException-
返されるエントリーがファイルで、ディレクトリーではないとき投げられます。
NotFoundErrorDOMException-
ディレクトリーが存在せず、
createオプションがfalseに設定されているとき投げられます。
例
以下の例では、指定した名前のディレクトリーハンドルを返します。ディレクトリーが存在しない場合、作成されます。
js
const dirName = "directoryToGetName";
// ディレクトリーハンドル 'currentDirHandle' があると仮定
const subDir = currentDirHandle.getDirectoryHandle(dirName, { create: true });
仕様書
| 仕様書 |
|---|
| File System> # api-filesystemdirectoryhandle-getdirectoryhandle> |