title | slug | page-type | tags | browser-compat | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
StorageManager.getDirectory() |
Web/API/StorageManager/getDirectory |
web-api-instance-method |
|
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.
getDirectory()
None.
A {{jsxref('Promise')}} that fulfills with a {{domxref("FileSystemDirectoryHandle")}} object.
SecurityError
{{domxref("DOMException")}}- : Thrown if the user agent is not able to map the requested directory to the local OPFS.
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}}
{{Compat}}
- {{domxref("StorageManager")}}
- {{domxref("navigator.storage")}}
- {{domxref("FileSystemDirectoryHandle")}}