FileSystemDirectoryHandle.getFileHandle()
安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。
FileSystemDirectoryHandle インターフェイスの getFileHandle() メソッドは、メソッドが呼ばれたディレクトリー内の指定した名前のファイルを表す FileSystemFileHandle を返します。
構文
js
getFileHandle(name)
getFileHandle(name, options)
引数
name-
取得したいファイルの
FileSystemHandle.nameを表す文字列です。 options省略可-
以下のプロパティを持つオブジェクトです。
create-
Booleanです。デフォルトはfalseです。trueに設定すると、ファイルが見つからない場合、指定した名前のファイルが作成されて返されます。
返値
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 Standard # api-filesystemdirectoryhandle-getfilehandle |
ブラウザーの互換性
BCD tables only load in the browser