![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi3_komaru-1.png)
カレントディレクトリを取得・設定するにはどうしたらいいですか?
![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi1_normal.png)
![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi1_normal.png)
![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi1_normal.png)
カレントディレクトリはGetCurrentDirectoryで取得、SetCurrentDirectoryで変更することができます。
目次
カレントディレクトリを取得・設定する
カレントディレクトリ(作業フォルダ)を取得・設定するには、EnvironmentクラスのCurrentDirectoryプロパティからも設定できます。
System.Environment.CurrentDirectory
また、DirectoryクラスのGetCurrentDirectoryメソッドを利用することでも、カレントディレクトリを取得できます。カレントディレクトリのパスを文字列で返します。
System.IO.Directory.GetCurrentDirectory()
DirectoryクラスのSetCurrentDirectoryメソッドを利用することでも、カレントディレクトリを変更できます。
引数にカレントディレクトリのパスを指定します。
System.IO.Directory.SetCurrentDirectory(フォルダパス)
Debug.WriteLine(System.Environment.CurrentDirectory);
Debug.WriteLine(System.IO.Directory.GetCurrentDirectory());
System.Environment.CurrentDirectory = @"C:\debug1";
System.IO.Directory.SetCurrentDirectory(@"C:\debug1");
Debug.WriteLine(System.Environment.CurrentDirectory)
Debug.WriteLine(System.IO.Directory.GetCurrentDirectory())
System.Environment.CurrentDirectory = "C:\debug1"
System.IO.Directory.SetCurrentDirectory("C:\debug1")
CHECK
現在は、Environmentクラスから取得・設定するのが主流です。
コメント