1# @ohos.file.trash (Trash) (System API)
2
3The **file.trash** module provides APIs for querying, recovering, or permanently deleting the files or folders in **Recently deleted** (trash). Currently, only local files and folders are supported.
4
5You can use **delete()** of [@ohos.file.fileAccess](js-apis-fileAccess-sys.md) to move a file or folder to the trash.
6
7>**NOTE**
8>
9> - 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.
10> - The APIs provided by this module are system APIs.
11> - Currently, the APIs of this module can be called only by **FileManager**.
12
13## Modules to Import
14
15```js
16import trash from '@ohos.file.trash';
17```
18
19## trash.listFile
20
21listFile(): Array\<FileInfo>
22
23Lists the files and folders in the **Recently deleted** list.
24
25**Model restriction**: This API can be used only in the stage model.
26
27**System capability**: SystemCapability.FileManagement.UserFileService
28
29**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
30
31**System API**: This is a system API.
32
33**Return value**
34
35  | Type| Description|
36  | --- | -- |
37  | Array [\<FileInfo>](#fileinfo) | List of the files and folders obtained.|
38
39**Error codes**
40
41For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
42
43**Example**
44
45  ```js
46  let fileinfos = trash.listFile();
47  for(let i = 0; i < fileinfos.length; i++){
48    console.info('uri: ' + fileinfos[i].uri);
49    console.info('srcPath: ' + fileinfos[i].srcPath);
50    console.info('fileName: ' + fileinfos[i].fileName);
51    console.info('mode: ' + fileinfos[i].mode);
52    console.info('size: ' + fileinfos[i].size);
53    console.info('mtime: ' + fileinfos[i].mtime);
54    console.info('ctime: ' + fileinfos[i].ctime);
55  }
56  ```
57
58## trash.recover
59
60recover(uri: string): void;
61
62Recovers a file or folder from the trash.
63
64**Model restriction**: This API can be used only in the stage model.
65
66**System capability**: SystemCapability.FileManagement.UserFileService
67
68**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
69
70**System API**: This is a system API.
71
72**Parameters**
73
74| Name| Type  | Mandatory| Description                      |
75| ------ | ------ | ---- | -------------------------- |
76| uri   | string | Yes  | URI of the file or folder to recover.|
77
78**Error codes**
79
80For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
81
82**Example**
83
84  ```js
85  let fileinfos = trash.listFile();
86  let uri = fileinfos[0].uri;
87  trash.recover(uri);
88  ```
89
90## trash.completelyDelete
91
92completelyDelete(uri: string): void
93
94Permanently deletes a file or folder from the **Recently deleted** list.
95
96**Model restriction**: This API can be used only in the stage model.
97
98**System capability**: SystemCapability.FileManagement.UserFileService
99
100**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
101
102**System API**: This is a system API.
103
104**Parameters**
105
106| Name| Type  | Mandatory| Description                      |
107| ------ | ------ | ---- | -------------------------- |
108| uri   | string | Yes  | URI of the file or folder to delete.|
109
110**Error codes**
111
112For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
113
114**Example**
115
116  ```js
117  let fileinfos = trash.listFile();
118  let uri = fileinfos[0].uri;
119  trash.completelyDelete(uri);
120  ```
121
122
123## FileInfo
124
125Represents information about a file or folder in the **Recently deleted** list.
126
127**Model restriction**: This API can be used only in the stage model.
128
129**System capability**: SystemCapability.FileManagement.UserFileService
130
131| Name| Type  | Read-Only| Writable| Description    |
132| ------ | ------ | -------- | ------ | -------- |
133| uri | string | Yes| No| URI of the file or folder.|
134| srcPath | string | Yes| No| Path of the file or folder before being deleted.|
135| fileName | string | Yes| No| Name of the file or folder.|
136| mode | number | Yes| No| Permission on the file or folder.|
137| size | number | Yes| No|  Size of the file or folder.|
138| mtime | number | Yes| No|  Time when the file or folder was last modified.|
139| ctime | string | Yes| No|  Time when the file or folder was created.|
140