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