1e41f4b71Sopenharmony_ci# Fileuri
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## 概述
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci文件统一资源标识符(File Uniform Resource Identifier),支持fileuri与路径path的转换、有效性校验、以及指向的变换(指向的文件或路径)。
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.FileManagement.AppFileService
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci**起始版本:** 12
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## 汇总
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci### 文件
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci| 名称 | 描述 | 
19e41f4b71Sopenharmony_ci| -------- | -------- |
20e41f4b71Sopenharmony_ci| [oh_file_uri.h](oh__file__uri_8h.md) | 提供uri和路径path之间的相互转换,目录uri获取,以及URi的有效性校验的方法。 | 
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci### 函数
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci| 名称                                                                                                                                                                                       | 描述                                              | 
26e41f4b71Sopenharmony_ci|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------|
27e41f4b71Sopenharmony_ci| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileUri_GetUriFromPath](#oh_fileuri_geturifrompath) (const char \*path, unsigned int length, char \*\*result)          | 将传入的路径path转换成uri。                               | 
28e41f4b71Sopenharmony_ci| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileUri_GetPathFromUri](#oh_fileuri_getpathfromuri) (const char \*uri, unsigned int length, char \*\*result)           | 将传入的uri转换成路径path。                               | 
29e41f4b71Sopenharmony_ci| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileUri_GetFullDirectoryUri](#oh_fileuri_getfulldirectoryuri) (const char \*uri, unsigned int length, char \*\*result) | 获取uri所在目录的uri,如果是文件uri则获取父目录的uri,如果是目录uri则返回本身。 | 
30e41f4b71Sopenharmony_ci| bool [OH_FileUri_IsValidUri](#oh_fileuri_isvaliduri) (const char \*uri, unsigned int length)                                                                                             | 校验传入的uri是否有效。                                   | 
31e41f4b71Sopenharmony_ci| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileUri_GetFileName](#oh_fileuri_getfilename) (const char \*uri, unsigned int length, char \*\*result)                 | 获取传入uri中的文件名称。                                  | 
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci## 函数说明
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci### OH_FileUri_GetFullDirectoryUri()
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci```
39e41f4b71Sopenharmony_ciFileManagement_ErrCode OH_FileUri_GetFullDirectoryUri (const char * uri, unsigned int length, char ** result )
40e41f4b71Sopenharmony_ci```
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**描述**
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci获取uri所在目录的uri,如果是文件uri则获取父目录的uri,如果是目录uri则返回本身。
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.FileManagement.AppFileService
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci**起始版本:** 12
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci**参数:**
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci| 名称 | 描述 | 
53e41f4b71Sopenharmony_ci| -------- | -------- |
54e41f4b71Sopenharmony_ci| uri | 表示要获取目录的uri的原始uri。 | 
55e41f4b71Sopenharmony_ci| length | 表示原始uri的字节长度。 | 
56e41f4b71Sopenharmony_ci| result | 表示获取到的目录URi, 需要使用standard library标准库的free()方法释放申请的资源。 | 
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**返回:**
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci返回特定的错误码值,详细信息可以查看[FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode)。
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci### OH_FileUri_GetPathFromUri()
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci```
66e41f4b71Sopenharmony_ciFileManagement_ErrCode OH_FileUri_GetPathFromUri (const char * uri, unsigned int length, char ** result )
67e41f4b71Sopenharmony_ci```
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci**描述**
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci将传入的uri转换成路径path。
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.FileManagement.AppFileService
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci**起始版本:** 12
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci**参数:**
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci| 名称 | 描述 | 
80e41f4b71Sopenharmony_ci| -------- | -------- |
81e41f4b71Sopenharmony_ci| uri | 表示要转换的uri。 | 
82e41f4b71Sopenharmony_ci| length | 表示要转换uri的字节长度。 | 
83e41f4b71Sopenharmony_ci| result | 表示转换后的路径path. 需要使用standard library标准库的free()方法释放申请的资源。 | 
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci**返回:**
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci返回特定的错误码值,详细信息可以查看[FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode)。
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci### OH_FileUri_GetUriFromPath()
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci```
93e41f4b71Sopenharmony_ciFileManagement_ErrCode OH_FileUri_GetUriFromPath (const char * path, unsigned int length, char ** result )
94e41f4b71Sopenharmony_ci```
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci**描述**
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci将传入的路径path转换成uri。
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.FileManagement.AppFileService
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci**起始版本:** 12
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**参数:**
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci| 名称 | 描述 | 
107e41f4b71Sopenharmony_ci| -------- | -------- |
108e41f4b71Sopenharmony_ci| path | 表示要转换的路径。 | 
109e41f4b71Sopenharmony_ci| length | 表示要转换路径的字节长度。 | 
110e41f4b71Sopenharmony_ci| result | 表示转换后的uri, 需要使用standard library标准库的free()方法释放申请的资源。 | 
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci**返回:**
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci返回特定的错误码值,详细信息可以查看[FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode)。
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci### OH_FileUri_IsValidUri()
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci```
120e41f4b71Sopenharmony_cibool OH_FileUri_IsValidUri (const char * uri, unsigned int length )
121e41f4b71Sopenharmony_ci```
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci**描述**
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci校验传入的uri是否有效。
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.FileManagement.AppFileService
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci**起始版本:** 12
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci**参数:**
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci| 名称 | 描述 | 
134e41f4b71Sopenharmony_ci| -------- | -------- |
135e41f4b71Sopenharmony_ci| uri | 表示需要校验的uri。 | 
136e41f4b71Sopenharmony_ci| length | 需要校验uri的字节长度。 | 
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**返回:**
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci返回true表示传入uri是有效的uri;返回false表示传入的uri是无效的uri。
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci### OH_FileUri_GetFileName()
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci```
145e41f4b71Sopenharmony_ciFileManagement_ErrCode OH_FileUri_GetFileName (const char * uri, unsigned int length, char ** result )
146e41f4b71Sopenharmony_ci```
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci**描述**
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci获取传入的uri中的文件名称。
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.FileManagement.AppFileService
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci**起始版本:** 13
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci**参数:**
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci| 名称 | 描述                                                   | 
159e41f4b71Sopenharmony_ci| -------- |------------------------------------------------------|
160e41f4b71Sopenharmony_ci| uri | 表示传入的uri。                                            | 
161e41f4b71Sopenharmony_ci| length | 表示传入uri的字节长度。                                        | 
162e41f4b71Sopenharmony_ci| result | 表示获取到的文件名称. 需要使用standard library标准库的free()方法释放申请的资源。 | 
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci**返回:**
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci返回特定的错误码值,详细信息可以查看[FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode)。