DirectoryInfo コンストラクタとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DirectoryInfo コンストラクタの意味・解説 

DirectoryInfo コンストラクタ

指定したパス対する、DirectoryInfo クラス新しインスタンス初期化します。

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

public DirectoryInfo (
    string path
)
public:
DirectoryInfo (
    String^ path
)
public DirectoryInfo (
    String path
)
public function DirectoryInfo (
    path : String
)

パラメータ

path

DirectoryInfo作成する対象パス指定する文字列

例外例外
例外種類条件

ArgumentNullException

pathnull 参照 (Visual Basic では Nothing) です。

SecurityException

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

ArgumentException

path に、"、<、>、| などの無効な文字含まれています。

PathTooLongException

指定したパスファイル名、またはその両方システム定義の最大長を超えてます。たとえば、Windows ベースプラットフォーム場合パス長さ248 文字未満ファイル名長さ260 文字未満である必要があります指定したパスファイル名、またはその両方が長すぎます

解説解説

このコンストラクタは、ディレクトリ存在するかどうかチェック行いません。このコンストラクタは、以降操作ディスクへのアクセス使用される文字列のプレースホルダです。

path パラメータにはファイル名指定できます。このファイルには、UNC 共有ファイル含まれます。

注意に関するメモ注意

特定のカルチャ設定文字セットコンパイルし、同じ文字異なるカルチャ設定取得すると、文字正しく解釈されない場合があり、例外スローされることもあります

その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します

使用例使用例

指定したディレクトリサブディレクトリをこのコンストラクタ使用して作成し、さらにサブディレクトリを含むディレクトリ削除できないようすを表す例を次に示します

Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        ' Specify the directories you want to manipulate.
        Dim di1 As DirectoryInfo = New
 DirectoryInfo("c:\MyDir")
        Dim di2 As DirectoryInfo = New
 DirectoryInfo("c:\MyDir\temp")
        Try
            ' Create the directories.
            di1.Create()
            di2.Create()
            ' This operation will not be allowed because there are subdirectories.
            Console.WriteLine("I am about to attempt to delete
 {0}.", di1.Name)
            di1.Delete()
            Console.WriteLine("The Delete operation was successful,
 which was unexpected.")
        Catch e As Exception
            Console.WriteLine("The Delete operation failed as
 expected.")
        End Try
    End Sub
End Class
using System;
using System.IO;

class Test 
{
    public static void Main()
 
    {
        // Specify the directories you want to manipulate.
        DirectoryInfo di1 = new DirectoryInfo(@"c:\MyDir");
        DirectoryInfo di2 = new DirectoryInfo(@"c:\MyDir\temp");

        try 
        {
            // Create the directories.
            di1.Create();
            di2.Create();

            // This operation will not be allowed because there are
 subdirectories.
            Console.WriteLine("I am about to attempt to delete {0}.", di1.Name);
            di1.Delete();
            Console.WriteLine("The Delete operation was successful, which was
 unexpected.");
        } 
        catch (Exception) 
        {
            Console.WriteLine("The Delete operation failed as expected.");
        } 
        finally {}
    }
}
using namespace System;
using namespace System::IO;
int main()
{
   
   // Specify the directories you want to manipulate.
   DirectoryInfo^ di1 = gcnew DirectoryInfo( "c:\\MyDir" );
   DirectoryInfo^ di2 = gcnew DirectoryInfo( "c:\\MyDir\\temp" );
   try
   {
      
      // Create the directories.
      di1->Create();
      di2->Create();
      
      // This operation will not be allowed because there are subdirectories.
      Console::WriteLine( "I am about to attempt to delete {0}.", di1->Name
 );
      di1->Delete();
      Console::WriteLine( "The Delete operation was successful, which was unexpected."
 );
   }
   catch ( Exception^ ) 
   {
      Console::WriteLine( "The Delete operation failed as expected." );
   }

}

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

class Test
{
    public static void main(String[]
 args)
    {
        // Specify the directories you want to manipulate.
        DirectoryInfo di1 = new DirectoryInfo("c:\\MyDir");
        DirectoryInfo di2 = new DirectoryInfo("c:\\MyDir\\temp");

        try {
            // Create the directories.
            di1.Create();
            di2.Create();

            // This operation will not be allowed because there
            // are subdirectories.
            Console.WriteLine("I am about to attempt to delete {0}.",
                di1.get_Name());
            di1.Delete();
            Console.WriteLine("The Delete operation was successful, "
                + "which was unexpected.");
        }
        catch (System.Exception exp) {
            Console.WriteLine("The Delete operation failed as expected.");
        }
        finally {
        }
    } //main
} //Test
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「DirectoryInfo コンストラクタ」の関連用語

DirectoryInfo コンストラクタのお隣キーワード
検索ランキング

   

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



DirectoryInfo コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS