files/en-us/web/api/filesystemdirectoryhandle/getdirectoryhandle/index.md
{{securecontext_header}}{{APIRef("File System API")}}{{AvailableInWorkers}}
The getDirectoryHandle() method of the
{{domxref("FileSystemDirectoryHandle")}} interface returns a
{{domxref('FileSystemDirectoryHandle')}} for a subdirectory with the specified name
within the directory handle on which the method is called.
getDirectoryHandle(name)
getDirectoryHandle(name, options)
name
options {{optional_inline}}
create {{optional_inline}}
false. When
set to true if the directory is not found, one with the specified
name will be created and returned.A {{jsxref('Promise')}} which resolves with a {{domxref('FileSystemDirectoryHandle')}}.
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 directory handle with the specified name, if the directory does not exist it is created.
const dirName = "directoryToGetName";
// assuming we have a directory handle: 'currentDirHandle'
const subDir = await currentDirHandle.getDirectoryHandle(dirName, {
create: true,
});
{{Specifications}}
{{Compat}}