1# @ohos.file.environment (Directory Environment Capability) 2 3The **Environment** module provides APIs for obtaining the root directories of the storage and user files. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import { Environment } from '@kit.CoreFileKit'; 13``` 14 15## Environment.getUserDownloadDir<sup>11+</sup> 16 17getUserDownloadDir(): string 18 19Obtains the sandbox path of the pre-authorized **Download** directory. 20 21**System capability**: SystemCapability.FileManagement.File.Environment.FolderObtain 22 23**Return value** 24 25| Type | Description | 26| --------------------- |---------------------| 27| string | Sandbox path of the **Download** directory obtained.| 28 29**Error codes** 30 31For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 32 33| ID | Error Message | 34|----------| --------- | 35| 801 | Capability not supported. | 36| 13900042 | Unknown error | 37 38**Example** 39 40```ts 41import { BusinessError } from '@kit.BasicServicesKit'; 42function getUserDownloadDirExample() { 43 try { 44 let path = Environment.getUserDownloadDir(); 45 console.log(`success to getUserDownloadDir: ${JSON.stringify(path)}`); 46 } catch (error) { 47 console.error(`failed to getUserDownloadDir because: ${JSON.stringify(error)}`); 48 } 49} 50``` 51 52## Environment.getUserDesktopDir<sup>11+</sup> 53 54getUserDesktopDir(): string 55 56Obtains the sandbox path of the pre-authorized **Desktop** directory. 57 58**System capability**: SystemCapability.FileManagement.File.Environment.FolderObtain 59 60**Return value** 61 62| Type | Description | 63| --------------------- |---------------------| 64| string | Sandbox path of the **Desktop** directory obtained.| 65 66**Error codes** 67 68For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 69 70| ID | Error Message | 71|----------| --------- | 72| 801 | Capability not supported. | 73| 13900042 | Unknown error | 74 75**Example** 76 77```ts 78import { BusinessError } from '@kit.BasicServicesKit'; 79function getUserDesktopDirExample() { 80 try { 81 let path = Environment.getUserDesktopDir(); 82 console.log(`success to getUserDesktopDir: ${JSON.stringify(path)}`); 83 } catch (error) { 84 console.error(`failed to getUserDesktopDir because: ${JSON.stringify(error)}`); 85 } 86} 87``` 88 89## Environment.getUserDocumentDir<sup>11+</sup> 90 91getUserDocumentDir(): string 92 93Obtains the sandbox path of the pre-authorized **Document** directory. 94 95**System capability**: SystemCapability.FileManagement.File.Environment.FolderObtain 96 97**Return value** 98 99| Type | Description | 100| --------------------- |---------------------| 101| string | Sandbox path of the **Documents** directory obtained.| 102 103**Error codes** 104 105For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 106 107| ID | Error Message | 108|----------| --------- | 109| 801 | Capability not supported. | 110| 13900042 | Unknown error | 111 112**Example** 113 114```ts 115import { BusinessError } from '@kit.BasicServicesKit'; 116function getUserDocumentDirExample() { 117 try { 118 let path = Environment.getUserDocumentDir(); 119 console.log(`success to getUserDocumentDir: ${JSON.stringify(path)}`); 120 } catch (error) { 121 console.error(`failed to getUserDocumentDir because: ${JSON.stringify(error)}`); 122 } 123} 124``` 125