1# Fileuri
2
3
4## Overview
5
6Provides APIs for manipulating file Uniform Resource Identifiers (URIs), including performing URI-path conversion, obtaining a URI, and verifying a URI.
7
8**System capability**: SystemCapability.FileManagement.AppFileService
9
10**Since**: 12
11
12
13## Summary
14
15
16### Files
17
18| Name| Description|
19| -------- | -------- |
20| [oh_file_uri.h](oh__file__uri_8h.md) | Provides APIs for URI operations, including URI-path conversion, retrieval, and verification.|
21
22
23### Functions
24
25| Name                                                                                                                                                                                      | Description                                             |
26|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------|
27| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileUri_GetUriFromPath](#oh_fileuri_geturifrompath) (const char \*path, unsigned int length, char \*\*result)          | Obtains the URI from a path.                              |
28| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileUri_GetPathFromUri](#oh_fileuri_getpathfromuri) (const char \*uri, unsigned int length, char \*\*result)           | Obtains the path from a URI.                              |
29| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileUri_GetFullDirectoryUri](#oh_fileuri_getfulldirectoryuri) (const char \*uri, unsigned int length, char \*\*result) | Obtains the URI of the directory, in which a URI is located. If the specified URI points to a file, the URI of the parent directory is returned. If the specified URI points to a folder, the URI of the folder is returned.|
30| bool [OH_FileUri_IsValidUri](#oh_fileuri_isvaliduri) (const char \*uri, unsigned int length)                                                                                             | Checks whether a URI is valid.                                  |
31| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileUri_GetFileName](#oh_fileuri_getfilename) (const char \*uri, unsigned int length, char \*\*result)                 | Obtains the file name from the given URI.                                 |
32
33## Function Description
34
35
36### OH_FileUri_GetFullDirectoryUri()
37
38```
39FileManagement_ErrCode OH_FileUri_GetFullDirectoryUri (const char * uri, unsigned int length, char ** result )
40```
41
42**Description**
43
44Obtains the URI of the directory, in which a URI is located. If the specified URI points to a file, the URI of the parent directory is returned. If the specified URI points to a folder, the URI of the folder is returned.
45
46**System capability**: SystemCapability.FileManagement.AppFileService
47
48**Since**: 12
49
50**Parameters**
51
52| Name| Description|
53| -------- | -------- |
54| uri | Pointer to the target URI.|
55| length | Length of the URI, in bytes.|
56| result | Double pointer to the URI obtained. You also need to use **free()** of the standard library to release the memory allocated.|
57
58**Returns**
59
60Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode).
61
62
63### OH_FileUri_GetPathFromUri()
64
65```
66FileManagement_ErrCode OH_FileUri_GetPathFromUri (const char * uri, unsigned int length, char ** result )
67```
68
69**Description**
70
71Obtains the path from a URI.
72
73**System capability**: SystemCapability.FileManagement.AppFileService
74
75**Since**: 12
76
77**Parameters**
78
79| Name| Description|
80| -------- | -------- |
81| uri | Pointer to the URI to convert.|
82| length | Length of the URI to convert.|
83| result | Double pointer to the path obtained. You also need to use **free()** of the standard library to release the memory allocated.|
84
85**Returns**
86
87Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode).
88
89
90### OH_FileUri_GetUriFromPath()
91
92```
93FileManagement_ErrCode OH_FileUri_GetUriFromPath (const char * path, unsigned int length, char ** result )
94```
95
96**Description**
97
98Obtains the URI from a path.
99
100**System capability**: SystemCapability.FileManagement.AppFileService
101
102**Since**: 12
103
104**Parameters**
105
106| Name| Description|
107| -------- | -------- |
108| path | Pointer to the path to convert.|
109| length | Length of the path to convert.|
110| result | Double pointer to the URI obtained. You also need to use **free()** of the standard library to release the memory allocated.|
111
112**Returns**
113
114Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode).
115
116
117### OH_FileUri_IsValidUri()
118
119```
120bool OH_FileUri_IsValidUri (const char * uri, unsigned int length )
121```
122
123**Description**
124
125Checks whether a URI is valid.
126
127**System capability**: SystemCapability.FileManagement.AppFileService
128
129**Since**: 12
130
131**Parameters**
132
133| Name| Description|
134| -------- | -------- |
135| uri | Pointer to the URI to check.|
136| length | Length of the URI to check.|
137
138**Returns**
139
140Returns **true** if the URI is valid; returns **false** otherwise.
141
142### OH_FileUri_GetFileName()
143
144```
145FileManagement_ErrCode OH_FileUri_GetFileName (const char * uri, unsigned int length, char ** result )
146```
147
148**Description**
149
150Obtains the file name from the given URI.
151
152**System capability**: SystemCapability.FileManagement.AppFileService
153
154**Since**: 13
155
156**Parameters**
157
158| Name| Description                                                  |
159| -------- |------------------------------------------------------|
160| uri | Pointer to the URI.                                           |
161| length | Length of the URI, in bytes.                                       |
162| result | Double pointer to the file name obtained. You also need to use **free()** of the standard library to release the memory allocated.|
163
164**Returns**
165
166Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode).
167