0

基本的なVB.netの知識が不足していることをお詫びしますが、%systemdrive%に相当するものを使用して、VB.netの既存のディレクトリを確認するためにWindowsを含むドライブを見つけようとしています-したがって、以下があります。

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文字列を使用するのを手伝ってくれる人はいますか? ありがとうございました。

4

2 に答える 2

1

まあ書いた方がいい

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% という環境変数を取得できますが、得られた結果を現在のディレクトリ区切り文字 ( "\")と手動で組み合わせる必要があります。システム ドライブ (IE C:)

Dim sysDrive = Environment.GetEnvironmentVariable("SystemDrive") 
Dim myPath = sysDrive & Path.DirectorySeparatorChar & "MyFolder" 
于 2013-10-02T13:00:53.737 に答える
0

IO.Pathには、IMHOを使用する必要があるメソッドがあります

    Dim sysDrive As String = Environment.GetEnvironmentVariable("SystemDrive") & IO.Path.DirectorySeparatorChar
    Dim myPath As String = IO.Path.Combine(sysDrive, "FolderName")
于 2013-10-02T13:19:58.497 に答える