Origin private file system
The FileSystemDirectoryHandle interface of the File System API provides a handle to a file system directory.
The interface can be accessed via the window.showDirectoryPicker(), StorageManager.getDirectory(), DataTransferItem.getAsFileSystemHandle(), and FileSystemDirectoryHandle.getDirectoryHandle() methods.
FileSystemHandle FileSystemDirectoryHandle
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 86 | 86 | 111 | 15.2 | 109 | 15.2 | |
| The entries() method of the FileSystemDirectoryHandle interface returns a new asynchronous iterator for the iteration of the key-value pairs of the entries within the FileSystemDirectoryHandle on which this method is called. The key-value pairs are in the form of an array like [key, value]. | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
| The getDirectoryHandle() method of the FileSystemDirectoryHandle interface returns a FileSystemDirectoryHandle for a subdirectory with the specified name within the directory handle on which the method is called. | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
| The getFileHandle() method of the FileSystemDirectoryHandle interface returns a FileSystemFileHandle for a file with the specified name, within the directory the method is called. | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
| The keys() method of the FileSystemDirectoryHandle interface returns a new asynchronous iterator for the iteration of the key of the entries within the FileSystemDirectoryHandle on which this method is called. | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
| The removeEntry() method of the FileSystemDirectoryHandle interface attempts to remove an entry if the directory handle contains a file or directory called the name specified. | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
| The resolve() method of the FileSystemDirectoryHandle interface returns an Array of directory names from the parent handle to the specified child entry, with the name of the child entry as the last array item. | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
| The values() method of the FileSystemDirectoryHandle interface returns a new asynchronous iterator for the iteration of the value of the entries within the FileSystemDirectoryHandle on which this method is called. | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
| The FileSystemFileHandle interface of the File System API represents a handle to a file system entry. The interface is accessed through the window.showOpenFilePicker() method. | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
| The createSyncAccessHandle() method of the FileSystemFileHandle interface returns a Promise which resolves to a FileSystemSyncAccessHandle object that can be used to synchronously read from and write to a file. The synchronous nature of this method brings performance advantages, but it is only usable inside dedicated Web Workers for files within the origin… | 102 | 102 | 111 | 15.2 | 109 | 15.2 |
| The getFile() method of the FileSystemFileHandle interface returns a Promise which resolves to a File object representing the state on disk of the entry represented by the handle. | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
| The FileSystemHandle interface of the File System API is an object which represents a file or directory entry. Multiple handles can represent the same entry. For the most part you do not work with FileSystemHandle directly but rather its child interfaces FileSystemFileHandle and FileSystemDirectoryHandle. | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
| The isSameEntry() method of the FileSystemHandle interface compares two FileSystemHandle to see if the associated entries (either a file or directory) match. | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
| The kind read-only property of the FileSystemHandle interface returns the type of entry. This is 'file' if the associated entry is a file or 'directory'. It is used to distinguish files from directories when iterating over the contents of a directory. | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
| The name read-only property of the FileSystemHandle interface returns the name of the entry represented by handle. | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
| The FileSystemSyncAccessHandle interface of the File System API represents a synchronous handle to a file system entry. | 102 | 102 | 111 | 15.2 | 109 | 15.2 |
| The close() method of the FileSystemSyncAccessHandle interface closes an open synchronous file handle, disabling any further operations on it and releasing the exclusive lock previously put on the file associated with the file handle. | 102 | 102 | 111 | 15.2 | 109 | 15.2 |
close (sync version) Synchronous implementation of the `close()` method | 108 | 108 | 111 | 16.4 | 109 | 16.4 |
| The flush() method of the FileSystemSyncAccessHandle interface persists any changes made to the file associated with the handle via the FileSystemSyncAccessHandle.write method to disk. | 102 | 102 | 111 | 15.2 | 109 | 15.2 |
flush (sync version) Synchronous implementation of the `flush()` method | 108 | 108 | 111 | 16.4 | 109 | 16.4 |
| The getSize() method of the FileSystemSyncAccessHandle interface returns the size of the file associated with the handle in bytes. | 102 | 102 | 111 | 15.2 | 109 | 15.2 |
getSize (sync version) Synchronous implementation of the `getSize()` method | 108 | 108 | 111 | 16.4 | 109 | 16.4 |
| The read() method of the FileSystemSyncAccessHandle interface reads the content of the file associated with the handle into a specified buffer, optionally at a given offset. | 102 | 102 | 111 | 15.2 | 109 | 15.2 |
| The truncate() method of the FileSystemSyncAccessHandle interface resizes the file associated with the handle to a specified number of bytes. | 102 | 102 | 111 | 15.2 | 109 | 15.2 |
truncate (sync version) Synchronous implementation of the `truncate()` method | 108 | 108 | 111 | 16.4 | 109 | 16.4 |
| The write() method of the FileSystemSyncAccessHandle interface writes the content of a specified buffer to the file associated with the handle, optionally at a given offset. | 102 | 102 | 111 | 15.2 | 109 | 15.2 |
| The getDirectory() method of the StorageManager interface is used to obtain a reference to a FileSystemDirectoryHandle object allowing access to a directory and its contents, stored in the origin private file system (OPFS). | 86 | 86 | 111 | 15.2 | 109 | 15.2 |
Use cases
-
Using Origin private file system
The FileSystemDirectoryHandle interface of the File System API provides a handle to a file system directory.
Cautions
- May not be supported in older browsers.
Implementation notes
- Some APIs require a secure context (HTTPS) or user activation. Check the requirements before use.