files/en-us/web/api/filesystemdirectoryhandle/getfilehandle/index.md
{{securecontext_header}}{{APIRef("File System API")}}{{AvailableInWorkers}}
The getFileHandle() method of the
{{domxref("FileSystemDirectoryHandle")}} interface returns a
{{domxref('FileSystemFileHandle')}} for a file with the specified name, within the
directory the method is called.
getFileHandle(name)
getFileHandle(name, options)
name
options {{optional_inline}}
create {{optional_inline}}
false. When
set to true if the file is not found, one with the specified name
will be created and returned.A {{jsxref('Promise')}} which resolves with a {{domxref('FileSystemFileHandle')}}.
NotAllowedError {{domxref("DOMException")}}
'granted' in readwrite mode if the create option is set to true or in read mode if the create option is set to false.TypeMismatchError {{domxref("DOMException")}}
NotFoundError {{domxref("DOMException")}}
create option is set to
false.The following example returns a file handle with the specified name, if the file does not exist it is created.
const fileName = "fileToGetName";
// assuming we have a directory handle: 'currentDirHandle'
const fileHandle = await currentDirHandle.getFileHandle(fileName, {
create: true,
});
{{Specifications}}
{{Compat}}