openharmony 鸿蒙 js-apis-file-recent-sys

2025-06-12 浏览 (1)

@ohos.file.recent (Latest Access List) (System API)

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.
  • Currently, the APIs of this module 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 and folders 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

NameTypeRead-OnlyWritableDescription
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 鸿蒙Core File Kit

harmony 鸿蒙Environment

harmony 鸿蒙FileIO

harmony 鸿蒙FileShare_PolicyErrorResult

harmony 鸿蒙FileShare_PolicyInfo

harmony 鸿蒙error_code.h

harmony 鸿蒙File Management Error Codes

harmony 鸿蒙FileShare

harmony 鸿蒙FileUri

harmony 鸿蒙@ohos.application.BackupExtensionAbility (Backup and Restore Extension Capability) (System API)

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