Environment.CurrentDirectory プロパティ
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
現在の作業ディレクトリの完全修飾パスを取得または設定します。
public:
static property System::String ^ CurrentDirectory { System::String ^ get(); void set(System::String ^ value); };
C#
public static string CurrentDirectory { get; set; }
static member CurrentDirectory : string with get, set
Public Shared Property CurrentDirectory As String
ディレクトリのパスです。
空の文字列 ("") に設定しようとしました。
null
に設定しようとしました。
I/O エラーが発生しました。
見つからないローカル パスを設定しようとしました。
呼び出し元に、該当するアクセス許可がありません。
次の例では、 プロパティの設定を CurrentDirectory 示します。
using namespace System;
using namespace System::IO;
void main()
{
if (Environment::OSVersion->Platform == PlatformID::Win32NT)
{
// Change the directory to %WINDIR%
Environment::CurrentDirectory = Environment::GetEnvironmentVariable( "windir" );
DirectoryInfo^ info = gcnew DirectoryInfo( "." );
Console::WriteLine("Directory Info: {0}", info->FullName);
}
else
{
Console::WriteLine("This example runs on Windows only.");
}
}
// The example displays output like the following on a .NET implementation running on Windows:
// Directory Info: C:\windows
// The example displays the following output on a .NET implementation on Unix-based systems:
// This example runs on Windows only.
C#
using System;
using System.IO;
public class Example
{
public static void Main()
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
// Change the directory to %WINDIR%
Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir");
DirectoryInfo info = new DirectoryInfo(".");
Console.WriteLine("Directory Info: " + info.FullName);
}
else
{
Console.WriteLine("This example runs on Windows only.");
}
}
}
// The example displays output like the following on a .NET implementation running on Windows:
// Directory Info: C:\windows
// The example displays the following output on a .NET implementation on Unix-based systems:
// This example runs on Windows only.
open System
open System.IO
if Environment.OSVersion.Platform = PlatformID.Win32NT then
// Change the directory to %WINDIR%
Environment.CurrentDirectory <- Environment.GetEnvironmentVariable "windir"
let info = DirectoryInfo "."
printfn $"Directory Info: {info.FullName}"
else
printfn "This example runs on Windows only."
// The example displays output like the following on a .NET implementation running on Windows:
// Directory Info: C:\windows
// The example displays the following output on a .NET implementation on Unix-based systems:
// This example runs on Windows only.
Imports System.IO
Module Example
Public Sub Main()
If Environment.OSVersion.Platform = PlatformID.Win32NT Then
' Change the directory to %WINDIR%
Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir")
Dim info As New DirectoryInfo(".")
Console.WriteLine("Directory Info: " + info.FullName)
Else
Console.WriteLine("This example runs on Windows only.")
End If
End Sub
End Module
' The example displays output like the following on a .NET implementation running on Windows:
' Directory Info: C:\windows
' The example displays the following output on a .NET implementation on Unix-based systems:
' This example runs on Windows only.
定義上、このプロセスがローカル ドライブまたはネットワーク ドライブのルート ディレクトリで開始される場合、このプロパティの値はドライブ名の後に末尾のスラッシュ ("C:\" など) が続きます。 このプロセスがサブディレクトリで開始される場合、このプロパティの値は、末尾のスラッシュ ("C:\mySubDirectory" など) のないドライブとサブディレクトリのパスです。
製品 | バージョン |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。