harmony 鸿蒙@ohos.file.trash (Trash)

2023-10-30 浏览 (551)

@ohos.file.trash (Trash)

The file.trash module provides APIs for querying, recovering, or permanently deleting the files or folders in Recently deleted (trash). Currently, only local files and folders are supported.

You can use delete() of @ohos.file.fileAccess to move a file or folder to the trash.

NOTE

  • The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • The APIs of this module are system APIs and can be called only by the file manager.

Modules to Import

import trash from '@ohos.file.trash';

trash.listFile

listFile(): Array<FileInfo>

Lists the files and folders in the Recently deleted list.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.FileManagement.UserFileService

Required permissions: ohos.permission.FILE_ACCESS_MANAGER

System API: This is a system API.

Return value

TypeDescription
Array<FileInfo>List of the files and folders obtained.

Error codes

For details about the error codes, see File Management Error Codes.

Example

let fileinfos = trash.listFile();
for(let i = 0; i < fileinfos.length; i++){
  console.info('uri: ' + fileinfos[i].uri);
  console.info('srcPath: ' + fileinfos[i].srcPath);
  console.info('fileName: ' + fileinfos[i].fileName);
  console.info('mode: ' + fileinfos[i].mode);
  console.info('size: ' + fileinfos[i].size);
  console.info('mtime: ' + fileinfos[i].mtime);
  console.info('ctime: ' + fileinfos[i].ctime);
}

trash.recover

recover(uri: string): void;

Recovers a file or folder from the trash.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.FileManagement.UserFileService

Required permissions: ohos.permission.FILE_ACCESS_MANAGER

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
uristringYesURI of the file or folder to recover.

Error codes

For details about the error codes, see File Management Error Codes.

Example

let fileinfos = trash.listFile();
let uri = fileinfos[0].uri;
trash.recover(uri);

trash.completelyDelete

completelyDelete(uri: string): void

Permanently deletes a file or folder from the Recently deleted list.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.FileManagement.UserFileService

Required permissions: ohos.permission.FILE_ACCESS_MANAGER

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
uristringYesURI of the file or folder to delete.

Error codes

For details about the error codes, see File Management Error Codes.

Example

let fileinfos = trash.listFile();
let uri = fileinfos[0].uri;
trash.completelyDelete(uri);

FileInfo

Represents information about a file or folder in the Recently deleted list.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.FileManagement.UserFileService

NameTypeReadableWritableDescription
uristringYesNoURI of the file or folder.
srcPathstringYesNoPath of the file or folder before being deleted.
fileNamestringYesNoName of the file or folder.
modenumberYesNoPermission on the file or folder.
sizenumberYesNoSize of the file or folder.
mtimenumberYesNoTime when the file or folder was last modified.
ctimestringYesNoTime when the file or folder was created.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/c798c1306143478887f64f2e61565413