files/en-us/web/api/filesystemdirectoryentry/removerecursively/index.md
{{APIRef("File and Directory Entries API")}}{{Deprecated_Header}}{{Non-standard_Header}}
The {{domxref("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 {{domxref("FileSystemEntry.remove()")}}.
removeRecursively(successCallback)
removeRecursively(successCallback, errorCallback)
successCallback
errorCallback {{optional_inline}}
None ({{jsxref("undefined")}}).
If an error occurs and an errorCallback was specified, it gets called with
a single parameter: a {{domxref("DOMException")}} object describing the error. The
{{domxref("DOMException.code")}} specifies what type of error occurred, as follows:
DOMException.INVALID_MODIFICATION_ERR
DOMException.NO_MODIFICATION_ALLOWED_ERR
DOMException.NOT_FOUND_ERR
DOMException.NOT_READABLE_ERR
DOMException.SECURITY_ERR
[!NOTE] 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
errorCallbackto watch for and handle this, perhaps by trying again.
directory.removeRecursively(
() => {
/* The directory was removed successfully */
},
() => {
/* an error occurred while removing the directory */
},
);
{{Compat}}