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