FileSystemDirectoryEntry: removeRecursively() method

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.

Phương thức removeRecursively() của giao diện FileSystemDirectoryEntry xóa thư mục cùng với toàn bộ nội dung của nó, lặp đệ quy qua toàn bộ cây con các tệp và thư mục con.

Để xóa một tệp đơn hoặc một thư mục rỗng, bạn cũng có thể sử dụng FileSystemEntry.remove().

Cú pháp

js
removeRecursively(successCallback)
removeRecursively(successCallback, errorCallback)

Tham số

successCallback

Một hàm được gọi khi quá trình xóa thư mục hoàn tất. Callback không có tham số.

errorCallback Optional

Một hàm được gọi nếu xảy ra lỗi khi cố gắng xóa cây thư mục. Nhận một DOMException mô tả lỗi xảy ra làm đầu vào.

Giá trị trả về

Không có (undefined).

Ngoại lệ

Nếu xảy ra lỗi và errorCallback được chỉ định, nó được gọi với một tham số đơn: đối tượng DOMException mô tả lỗi. DOMException.code chỉ định loại lỗi xảy ra:

DOMException.INVALID_MODIFICATION_ERR

Đã cố gắng xóa thư mục gốc; điều này không được phép.

DOMException.NO_MODIFICATION_ALLOWED_ERR

Trạng thái của hệ thống tệp không cho phép sửa đổi.

DOMException.NOT_FOUND_ERR

Thư mục được đại diện bởi FileSystemDirectoryEntry không còn tồn tại.

DOMException.NOT_READABLE_ERR

Thư mục không thể truy cập được; có thể nó đang được sử dụng bởi ứng dụng khác hoặc bị khóa ở cấp hệ điều hành.

DOMException.SECURITY_ERR

Thư mục không thể bị xóa vì lý do bảo mật.

Note: Nếu bạn cố gắng xóa một thư mục chứa một hoặc nhiều tệp không thể xóa, hoặc nếu xảy ra lỗi khi đang xóa nhiều tệp, một số tệp có thể không bị xóa. Bạn nên cung cấp errorCallback để theo dõi và xử lý điều này, có thể bằng cách thử lại.

Ví dụ

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

Tương thích trình duyệt

Xem thêm