VB.net是否在目录路径中使用字符串?

VB.net是否在目录路径中使用字符串?,vb.net,visual-studio-2010,Vb.net,Visual Studio 2010,我很抱歉我缺乏基本的VB.net知识,但我希望使用相当于%systemdrive%的方法来查找包含Windows的驱动器,以检查VB.net中的现有目录,因此我有以下内容 Dim systemPath As String = Mid(Environment.GetFolderPath(Environment.SpecialFolder.System), 1, 3) If Not Directory.Exists("'systemPath'\MyFolder") Then

我很抱歉我缺乏基本的VB.net知识,但我希望使用相当于%systemdrive%的方法来查找包含Windows的驱动器,以检查VB.net中的现有目录,因此我有以下内容

Dim systemPath As String = Mid(Environment.GetFolderPath(Environment.SpecialFolder.System), 1, 3)
        If Not Directory.Exists("'systemPath'\MyFolder") Then
            Directory.CreateDirectory("'systemPath'\MyFolder")
        End If
有人可以帮助在目录查询中使用systemPath字符串吗?谢谢你。

你应该写信

Dim systemPath As String = Mid(Environment.GetFolderPath(Environment.SpecialFolder.System), 1, 3)
If Not Directory.Exists(Path.Combine(systemPath, "MyFolder")) Then
        Directory.CreateDirectory(Path.Combine(systemPath, "MyFolder"))
End If
您可以使用environment.GetEnvironmentVariable获得名为%SYSTEMDRIVE%的环境变量,但随后应将获得的结果与当前目录分隔符char(
“\”
)手动组合,因为我没有找到任何说服路径的方法。组合以仅使用系统驱动器构建有效路径(即
C:


Path具有应在IMHO中使用的方法

    Dim sysDrive As String = Environment.GetEnvironmentVariable("SystemDrive") & IO.Path.DirectorySeparatorChar
    Dim myPath As String = IO.Path.Combine(sysDrive, "FolderName")

谢谢,我用了第一个片段。我的问题是学习如何将字符串组合到具有(“”)的字段中。谢谢你。
    Dim sysDrive As String = Environment.GetEnvironmentVariable("SystemDrive") & IO.Path.DirectorySeparatorChar
    Dim myPath As String = IO.Path.Combine(sysDrive, "FolderName")