1# @ohos.file.recent (Latest Access List) (System API) 2<!--Kit: Core File Kit--> 3<!--Subsystem: FileManagement--> 4<!--Owner: @wang_zhangjun; @zhuangzhuang--> 5<!--Designer: @wang_zhangjun; @zhuangzhuang; @renguang1116--> 6<!--Tester: @liuhonggang123; @yue-ye2; @juxiaopang--> 7<!--Adviser: @foryourself--> 8 9The **file.recent** module provides APIs for managing the list of recently accessed files. 10 11>**NOTE** 12> 13> - 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. 14> - The APIs provided by this module are system APIs. 15> - Currently, the APIs of this module can be called only by **FileManager**. 16 17## Modules to Import 18 19```js 20import recent from '@ohos.file.recent'; 21``` 22 23## recent.add 24 25add(uri: string): void 26 27Adds the file of the specified URI to the recent file list. 28 29**Model restriction**: This API can be used only in the stage model. 30 31**System capability**: SystemCapability.FileManagement.UserFileService 32 33**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER 34 35**System API**: This is a system API. 36 37**Parameters** 38 39| Name| Type | Mandatory| Description | 40| ------ | ------ | ---- | -------------------------- | 41| uri | string | Yes | URI of the file to add.| 42 43**Error codes** 44 45For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 46 47**Example** 48 49 ```js 50 let uri = 'file://docs/storage/Users/currentUser/<publicPath>'; 51 recent.add(uri); 52 ``` 53 54## recent.remove 55 56remove(uri: string): void 57 58Removes the file of the specified URI from the recent file list. 59 60**Model restriction**: This API can be used only in the stage model. 61 62**System capability**: SystemCapability.FileManagement.UserFileService 63 64**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER 65 66**System API**: This is a system API. 67 68**Parameters** 69 70| Name| Type | Mandatory| Description | 71| ------ | ------ | ---- | -------------------------- | 72| uri | string | Yes | URI of the file to remove.| 73 74**Error codes** 75 76For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 77 78**Example** 79 80 ```js 81 let uri = 'file://docs/storage/Users/currentUser/<publicPath>'; 82 recent.remove(uri); 83 ``` 84 85## recent.listFile 86 87listFile(): Array\<FileInfo> 88 89Lists the files that are accessed recently. 90 91**Model restriction**: This API can be used only in the stage model. 92 93**System capability**: SystemCapability.FileManagement.UserFileService 94 95**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER 96 97**System API**: This is a system API. 98 99**Return value** 100 101 | Type| Description| 102 | --- | -- | 103 | Array<[FileInfo](#fileinfo)> | List of the files.| 104 105**Error codes** 106 107For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 108 109**Example** 110 111 ```js 112 let fileinfos = recent.listFile(); 113 for(let i = 0; i < fileinfos.length; i++){ 114 console.info('uri: ' + fileinfos[i].uri); 115 console.info('srcPath: ' + fileinfos[i].srcPath); 116 console.info('fileName: ' + fileinfos[i].fileName); 117 console.info('mode: ' + fileinfos[i].mode); 118 console.info('size: ' + fileinfos[i].size); 119 console.info('mtime: ' + fileinfos[i].mtime); 120 console.info('ctime: ' + fileinfos[i].ctime); 121 } 122 ``` 123 124## FileInfo 125 126Represents information about the recent file list. 127 128**Model restriction**: This API can be used only in the stage model. 129 130**System capability**: SystemCapability.FileManagement.UserFileService 131 132| Name| Type | Read-Only| Optional| Description | 133| ------ | ------ | -------- | ------ | -------- | 134| uri | string | Yes| No| File URI.| 135| srcPath | string | Yes| No| File path.| 136| fileName | string | Yes| No| File name.| 137| mode | number | Yes| No| [Permissions on the file](js-apis-file-fs.md#stat).| 138| size | number | Yes| No| File size, in bytes.| 139| mtime | number | Yes| No| Time when the file was last modified.| 140| ctime | number | Yes| No| Time when the file was created.| 141