DirectoryInfo コンストラクタ
アセンブリ: mscorlib (mscorlib.dll 内)



このコンストラクタは、ディレクトリが存在するかどうかのチェックは行いません。このコンストラクタは、以降の操作でディスクへのアクセスに使用される文字列のプレースホルダです。
path パラメータにはファイル名も指定できます。このファイルには、UNC 共有のファイルも含まれます。
![]() |
---|
特定のカルチャ設定で文字セットをコンパイルし、同じ文字を異なるカルチャ設定で取得すると、文字が正しく解釈されない場合があり、例外がスローされることもあります。 |
その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。
Directory.Move DirectoryInfo.MoveTo | |
Directory.Delete DirectoryInfo.Delete | |
CreateDirectory | |
CreateSubdirectory | |
GetDirectories GetDirectories | |
GetFileSystemInfos | |
GetFileSystemInfos | |

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


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DirectoryInfo コンストラクタのページへのリンク