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

  • 2023-10-30
  • 浏览 (335)

@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

Name Type Mandatory Description
uri string Yes URI 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

Name Type Mandatory Description
uri string Yes URI 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

|Type|Description| |—|–| |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

Name Type Readable Writable Description
uri string Yes No URI of the file.
srcPath string Yes No File path.
fileName string Yes No File name.
mode number Yes No Permissions on the file.
size number Yes No File size, in bytes.
mtime number Yes No Time when the file was last modified.
ctime number Yes No Time 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)

0  赞