更新:2007 年 11 月
合并两个路径并返回格式正确的路径。
' Usage
Dim value As String = My.Computer.FileSystem.CombinePath(baseDirectory ,relativePath)
' Declaration
Public Function CombinePath( _
   ByVal baseDirectory As String, _
   ByVal relativePath As String _
) As String
参数
- baseDirectory 
 String。要合并的第一个路径。必选。
- relativePath 
 String。要合并的第二个路径。必选。
返回值
String.
异常
下面的情况可能会导致异常:
- 路径格式不正确 (ArgumentException)。
备注
此方法去除多余的斜杠标记字符以创建格式正确的路径。
任务
下表列出了涉及 My.Computer.FileSystem.CombinePath 方法的任务的示例。
| 要执行的操作 | 请参见 | 
|---|---|
| 合并目录路径和文件名 | 
示例
此示例将目录路径和文件名合并以创建格式正确的路径。
Dim fullPath As String
fullPath = My.Computer.FileSystem.CombinePath _
("C:\Documents and Settings\All Users\Documents\My Pictures", "picture.jpg")
此示例将两个路径合并以创建格式正确的路径。
Dim fullPath As String
fullPath = My.Computer.FileSystem.CombinePath _
("C:\Dir1\Dir2\Dir3", "..\Dir4\Dir5\File.txt")
此示例返回 C:\Dir1\Dir2\Dir4\Dir5\File.txt。
要求
命名空间:Microsoft.VisualBasic.MyServices
类:FileSystemProxy(提供对 FileSystem 的访问)
**程序集:**Visual Basic Runtime Library(位于 Microsoft.VisualBasic.dll 中)
按项目类型列出可用性
| 项目类型 | 可用 | 
|---|---|
| Windows 应用程序 | 是 | 
| 类库 | 是 | 
| 控制台应用程序 | 是 | 
| Windows 控件库 | 是 | 
| Web 控件库 | 是 | 
| Windows 服务 | 是 | 
| 网站 | 是 | 
权限
以下权限可能是必需的:
| 权限 | 说明 | 
|---|---|
| 控制访问文件和文件夹的能力。关联的枚举:Unrestricted。 |