The FileSystemDirectoryEntry interface of the File and Directory Entries API represents a directory in a file system. It provides methods which make it possible to access and manipulate the files in a directory, as well as to access the entries within the directory.
You can create a new directory by calling getDirectory(). If you want to create subdirectories, create each child directory in sequence. If you try creating a directory using a full path that includes parent directories that do not exist yet, an error is returned. So create the hierarchy by recursively adding a new path after creating the parent directory.
In the following code snippet, we create a directory called "Documents."
// Taking care of the browser-specific prefixes.
window.requestFileSystem =
window.requestFileSystem || window.webkitRequestFileSystem;
window.directoryEntry = window.directoryEntry || window.webkitDirectoryEntry;
// …
function onFs(fs) {
fs.root.getDirectory(
"Documents",
{ create: true },
(directoryEntry) => {
// directoryEntry.isFile === false
// directoryEntry.isDirectory === true
// directoryEntry.name === 'Documents'
// directoryEntry.fullPath === '/Documents'
},
onError,
);
}
// Opening a file system with temporary storage
window.requestFileSystem(TEMPORARY, 1024 * 1024 /* 1MB */, onFs, onError);
This interface has no properties of its own, but inherits properties from its parent interface, FileSystemEntry.
This interface inherits methods from its parent interface, FileSystemEntry.
createReader()Creates a FileSystemDirectoryReader object which can be used to read the entries in this directory.
getDirectory()Returns a FileSystemDirectoryEntry object representing a directory located at a given path, relative to the directory on which the method is called.
getFile()Returns a FileSystemFileEntry object representing a file located within the directory's hierarchy, given a path relative to the directory on which the method is called.
removeRecursively() Deprecated Non-standard
Removes the directory as well as all of its content, hierarchically iterating over its entire subtree of descendant files and directories.
| Specification |
|---|
| File and Directory Entries API> # api-directoryentry> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
FileSystemDirectoryEntry |
8 | 79 | 50 | 15 | 11.1 | 18 | 50 | 14 | 11.3 | 1.0 | 4.4 | 11.3 |
createReader |
13 | 79 | 50 | 15 | 11.1 | 18 | 50 | 14 | 11.3 | 1.0 | 4.4 | 11.3 |
getDirectory |
8 | 79 | 15 | 11.1 | 18 | 50In Firefox for Android, theerrorCallback's input parameter is a DOMException rather than a FileError object. |
14 | 11.3 | 1.0 | 4.4 | 11.3 | |
getFile |
8 | 79 | 15 | 11.1 | 18 | 50In Firefox for Android, theerrorCallback's input parameter is a DOMException rather than a FileError object. |
14 | 11.3 | 1.0 | 4.4 | 11.3 | |
removeRecursively |
8 | 79 | 50–52While theremoveRecursively() method existed, it immediately called the error callback with NS_ERROR_DOM_SECURITY_ERR. |
15 | No | 18 | 50–52While theremoveRecursively() method existed, it immediately called the error callback with NS_ERROR_DOM_SECURITY_ERR. |
14 | No | 1.0 | 4.4 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry