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