Directory.GetCurrentDirectory メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Directory.GetCurrentDirectory メソッドの意味・解説 

Directory.GetCurrentDirectory メソッド

アプリケーション現在の作業ディレクトリ取得します

名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function GetCurrentDirectory
 As String
Dim returnValue As String

returnValue = Directory.GetCurrentDirectory
public static string GetCurrentDirectory
 ()
public:
static String^ GetCurrentDirectory ()
public static String GetCurrentDirectory ()
public static function GetCurrentDirectory
 () : String

戻り値
現在の作業ディレクトリパス格納している文字列

例外例外
例外種類条件

UnauthorizedAccessException

呼び出し元に必要なアクセス許可がありません。

NotSupportedException

オペレーティング システムが、"現在のディレクトリ" 機能備えていない Windows CE です。

このメソッド.NET Compact Framework使用できますが、現在はサポートされていません。

解説解説
使用例使用例

GetCurrentDirectory メソッドコード例次に示します

Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        Try
            ' Get the current directory.
            Dim path As String
 = Directory.GetCurrentDirectory()
            Dim target As String
 = "c:\temp"
            Console.WriteLine("The current directory is {0}",
 path)
            If Directory.Exists(target) = False
 Then
                Directory.CreateDirectory(target)
            End If
            ' Change the current directory.
            Environment.CurrentDirectory = (target)
            If path.Equals(Directory.GetCurrentDirectory()) Then
                Console.WriteLine("You are in the temp directory.")
            Else
                Console.WriteLine("You are not in the temp directory.")
            End If
        Catch e As Exception
            Console.WriteLine("The process failed: {0}",
 e.ToString())
        End Try
    End Sub
End Class
using System;
using System.IO;

class Test 
{
    public static void Main()
 
    {
        try 
        {
            // Get the current directory.
            string path = Directory.GetCurrentDirectory();
            string target = @"c:\temp";
            Console.WriteLine("The current directory is {0}", path);
            if (!Directory.Exists(target)) 
            {
                Directory.CreateDirectory(target);
            }

            // Change the current directory.
            Environment.CurrentDirectory = (target);
            if (path.Equals(Directory.GetCurrentDirectory()))
 
            {
                Console.WriteLine("You are in the temp directory.");
            } 
            else 
            {
                Console.WriteLine("You are not in the temp
 directory.");
            }
        } 
        catch (Exception e) 
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}
using namespace System;
using namespace System::IO;
int main()
{
   try
   {
      
      // Get the current directory.
      String^ path = Directory::GetCurrentDirectory();
      String^ target = "c:\\temp";
      Console::WriteLine( "The current directory is {0}", path );
      if (  !Directory::Exists( target ) )
      {
         Directory::CreateDirectory( target );
      }
      
      // Change the current directory.
      Environment::CurrentDirectory = target;
      if ( path->Equals( Directory::GetCurrentDirectory() )
 )
      {
         Console::WriteLine( "You are in the temp directory."
 );
      }
      else
      {
         Console::WriteLine( "You are not in the temp directory."
 );
      }
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "The process failed: {0}", e );
   }

}

import System.*;
import System.IO.*;

class Test
{
    public static void main(String[]
 args)
    {
        try {
            // Get the current directory.
            String path = Directory.GetCurrentDirectory();
            String target = "c:\\temp";

            Console.WriteLine("The current directory is {0}", path);
            if (!(Directory.Exists(target))) {
                Directory.CreateDirectory(target);
            }

            // Change the current directory.
            Environment.set_CurrentDirectory(target);
            if (path.Equals(Directory.GetCurrentDirectory()))
 {
                Console.WriteLine("You are in the temp directory.");
            }
            else {
                Console.WriteLine("You are not in the temp
 directory.");
            }
        }
        catch (System.Exception e) {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    } //main
} //Test
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からDirectory.GetCurrentDirectory メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDirectory.GetCurrentDirectory メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDirectory.GetCurrentDirectory メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Directory.GetCurrentDirectory メソッド」の関連用語

Directory.GetCurrentDirectory メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Directory.GetCurrentDirectory メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS