FileSystemDirectoryHandle.getFileHandle()
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 インターフェイスの getFileHandle() メソッドは、メソッドが呼ばれたディレクトリー内の指定した名前のファイルを表す FileSystemFileHandle を返します。
構文
js
getFileHandle(name)
getFileHandle(name, options)
引数
name-
取得したいファイルの
FileSystemHandle.nameを表す文字列です。 options省略可-
以下のプロパティを持つオブジェクトです。
返値
FileSystemFileHandle で解決する Promise を返します。
例外
NotAllowedErrorDOMException-
PermissionStatusが'granted'でないとき投げられます。 TypeError-
指定された名前が有効な文字列でないか、ネイティブのファイルシステムで支障が出る文字を含むとき投げられます。
TypeMismatchErrorDOMException-
指定されたエントリーがディレクトリーであってファイルではないとき投げられます。
NotFoundErrorDOMException-
ファイルが存在せず、
createオプションがfalseに設定されているとき投げられます。
例
以下の例では、指定の名前のファイルハンドルを返します。ファイルが存在しない場合、作成されます。
js
const fileName = "fileToGetName";
// ディレクトリーハンドル 'currentDirHandle' があると仮定
const fileHandle = currentDirHandle.getFileHandle(fileName, { create: true });
仕様書
| Specification |
|---|
| File System> # api-filesystemdirectoryhandle-getfilehandle> |
ブラウザーの互換性
Loading…