FileSystemEntry: remove() 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 remove() của giao diện FileSystemEntry xóa tệp hoặc thư mục khỏi hệ thống tệp. Thư mục phải rỗng trước khi có thể xóa.

Để xóa đệ quy một thư mục cùng với tất cả nội dung và thư mục con của nó, hãy gọi FileSystemDirectoryEntry.removeRecursively() thay thế.

Cú pháp

js
remove(successCallback)
remove(successCallback, errorCallback)

Tham số

successCallback

Hàm được gọi sau khi tệp được xóa thành công.

errorCallback Optional

Callback tùy chọn được gọi nếu việc xóa tệp thất bại.

Giá trị trả về

None (undefined).

Ngoại lệ

DOMException.INVALID_MODIFICATION_ERR

Mục được chỉ định là thư mục gốc của hệ thống tệp, hoặc mục được chỉ định là thư mục không rỗng.

DOMException.INVALID_STATE_ERR

Trạng thái được cache của hệ thống tệp không nhất quán với trạng thái trên đĩa, do đó tệp không thể bị xóa vì lý do an toàn.

DOMException.NO_MODIFICATION_ALLOWED_ERR

Trạng thái của hệ thống tệp không cho phép xóa tệp hoặc thư mục.

DOMException.NOT_FOUND_ERR

Tệp hoặc thư mục không tồn tại.

DOMException.SECURITY_ERR

Mục không thể bị xóa do quyền hạn hoặc các hạn chế truy cập khác, hoặc vì có quá nhiều lệnh gọi đang được thực hiện trên tài nguyên tệp.

Ví dụ

Ví dụ này xóa một tệp làm việc tạm thời.

js
workingDirectory.getFile(
  "tmp/work-file.json",
  {},
  (fileEntry) => {
    fileEntry.remove(() => {
      /* the file was removed successfully */
    });
  },
  handleError,
);

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

Xem thêm