harmony 鸿蒙@ohos.file.recent (Recent File List)

2023-10-30 浏览 (478)

@ohos.file.recent (Recent File List)

The file.recent module provides APIs for managing the list of recently accessed files.

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 provided by this module are system APIs and cannot be called by third-party applications. Currently, the APIs can be called only by FileManager.

Modules to Import

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

recent.add

add(uri: string): void

Adds the file of the specified URI to the recent file 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 to add.

Error codes

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

Example

let uri = 'file://docs/storage/Users/currentUser/\<publicPath>';
recent.add(uri);

recent.remove

remove(uri: string): void

Removes the file of the specified URI from the recent file 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 to remove.

Error codes

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

Example

let uri = 'file://docs/storage/Users/currentUser/\<publicPath>';
recent.remove(uri);

recent.listFile

listFile(): Array<FileInfo>

Lists the files that are accessed recently.

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 obtained.

Error codes

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

Example

let fileinfos = recent.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);
}

FileInfo

Represents information about the recent file list.

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

System capability: SystemCapability.FileManagement.UserFileService

NameTypeReadableWritableDescription
uristringYesNoURI of the file.
srcPathstringYesNoFile path.
fileNamestringYesNoFile name.
modenumberYesNoPermissions on the file.
sizenumberYesNoFile size, in bytes.
mtimenumberYesNoTime when the file was last modified.
ctimenumberYesNoTime when the file 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/ace169dc002a4035887421521f72dae5