FileSystemDirectoryEntry.removeRecursively()

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The FileSystemDirectoryEntry interface's method removeRecursively() removes the directory as well as all of its content, hierarchically iterating over its entire subtree of descendant files and directories.

To remove a single file, or an empty directory, you can also use FileSystemEntry.remove().

Syntax

JavaScript
FileSystemDirectoryEntry.removeRecursively(successCallback[, errorCallback]);

Parameters

successCallback
A function to call once the directory removal process has completed. The callback has no parameters.
errorCallback Optional
A function to be called if an error occurs while attempting to remove the directory subtree. Receives a FileError describing the error which occurred as input.

Return value

undefined.

Errors

If an error occurs and an errorCallback was specified, it gets called with a single parameter: a FileError object describing the error. The FileError.code specifies what type of error occurred, as follows:

FileError.INVALID_MODIFICATION_ERR
An attempt was made to remove the root directory; this is not permitted.
FileError.NO_MODIFICATION_ALLOWED_ERR
The file system's state doesn't permit modification.
FileError.NOT_FOUND_ERR
The directory represented by the FileSystemDirectoryEntry no longer exists.
FileError.NOT_READABLE_ERR
The directory is not accessible; perhaps it's in use by another application or is locked at the operating system level.
FileError.SECURITY_ERR
The directory could not be removed for security reasons. Possible reasons include:
  • The directory and/or its contents may not be safe to access from a Web application.
  • Too many file system calls are being made.
  • Other security concerns as raised by the user agent or the operating system.

If you try to delete a directory which contains one or more files that can't be removed, or if an error occurs while deletion of a number of files is underway, some files may not be deleted. You should provide an errorCallback to watch for and handle this, perhaps by trying again.

Example

JavaScript
directory.removeRecursively(function() {
  /* The directory was removed successfully */
}, function() {
  /* an error occurred while removing the directory */
});

Specifications

Specification Status Comment
File and Directory Entries API
The definition of 'getDirectory()' in that specification.
Editor's Draft Initial specification.

This API has no official W3C or WHATWG specification.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 13 webkit No support[1] No support No support No support
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support No support 0.16webkit No support[1] No support No support No support

[1] Although this method exists in Firefox 50, it currently immediately calls the errorCallback with an NS_ERROR_DOM_NOT_SUPPORTED error.

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/filesystemdirectoryentry/removerecursively

API File and Directory Entries API File System API Files FileSystemDirectoryEntry Method Non-Standard Non-standard Reference removeRecursively