Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. FileSystemDirectoryHandle
  4. getFileHandle()

FileSystemDirectoryHandle: getFileHandle() method

Baseline Widely available

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

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Note: This feature is available inWeb Workers.

ThegetFileHandle() method of theFileSystemDirectoryHandle interface returns aFileSystemFileHandle for a file with the specified name, within thedirectory the method is called.

Syntax

js
getFileHandle(name)getFileHandle(name, options)

Parameters

name

A string representing theFileSystemHandle.name ofthe file you wish to retrieve.

optionsOptional

An object with the following properties:

createOptional

ABoolean. Defaultfalse. Whenset totrue if the file is not found, one with the specified namewill be created and returned.

Return value

APromise which resolves with aFileSystemFileHandle.

Exceptions

NotAllowedErrorDOMException

Thrown if thePermissionStatus.state for the handle is not'granted' inreadwrite mode if thecreate option is set totrue or inread mode if thecreate option is set tofalse.

TypeError

Thrown if the name specified is not a valid string or contains characters that wouldinterfere with the native file system.

TypeMismatchErrorDOMException

Thrown if the named entry is a directory and not a file.

NotFoundErrorDOMException

Thrown if the current entry is not found or if the file doesn't exist and thecreate option is set tofalse.

Examples

The following example returns a file handle with the specified name, if the file doesnot exist it is created.

js
const fileName = "fileToGetName";// assuming we have a directory handle: 'currentDirHandle'const fileHandle = await currentDirHandle.getFileHandle(fileName, {  create: true,});

Specifications

Specification
File System
# api-filesystemdirectoryhandle-getfilehandle

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp