Skip to content

Latest commit

 

History

History
71 lines (50 loc) · 1.63 KB

File metadata and controls

71 lines (50 loc) · 1.63 KB
title slug page-type tags browser-compat
StorageManager.getDirectory()
Web/API/StorageManager/getDirectory
web-api-instance-method
API
Method
Quota
Reference
Secure context
Storage
Storage API
StorageManager
Usage
getDirectory
api.StorageManager.getDirectory

{{securecontext_header}}{{APIRef("Storage")}}

The getDirectory() method of the {{domxref("StorageManager")}} interface is used to obtain a reference to a {{domxref("FileSystemDirectoryHandle")}} object allowing access to a directory and its contents, stored in the origin private file system.

Syntax

getDirectory()

Parameters

None.

Return value

A {{jsxref('Promise')}} that fulfills with a {{domxref("FileSystemDirectoryHandle")}} object.

Exceptions

  • SecurityError {{domxref("DOMException")}}
    • : Thrown if the user agent is not able to map the requested directory to the local OPFS.

Examples

async function manipulateDirectory() {
  const root = await navigator.storage.getDirectory();

  // Create a new file handle.
  const fileHandle = await root.getFileHandle('Untitled.txt', { create: true });

  // Create a new directory handle.
  const dirHandle = await root.getDirectoryHandle('New Folder', { create: true });

  // Recursively remove a directory.
  await root.removeEntry('Old Stuff', { recursive: true });
}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("StorageManager")}}
  • {{domxref("navigator.storage")}}
  • {{domxref("FileSystemDirectoryHandle")}}