DirectoryInfo.Parent プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)

親ディレクトリ。または、パスが null であるか、ファイル パスがルート ("\"、"C:"、* "\\server\share" など) を示している場合は null 参照 (Visual Basic では Nothing)。


その他の一般的な 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 MoveToTest Public Shared Sub Main() ' Make a reference to a directory. Dim di As New DirectoryInfo("TempDir") ' Create the directory only if it does not already exist. If di.Exists = False Then di.Create() End If ' Create a subdirectory in the directory just created. Dim dis As DirectoryInfo = di.CreateSubdirectory("SubDir") ' Get a reference to the parent directory of the subdirectory you just made. Dim parentDir As DirectoryInfo = dis.Parent Console.WriteLine("The parent directory of '{0}' is '{1}'", dis.Name, parentDir.Name) ' Delete the parent directory. di.Delete(True) End Sub 'Main End Class 'MoveToTest
using System; using System.IO; public class MoveToTest { public static void Main() { // Make a reference to a directory. DirectoryInfo di = new DirectoryInfo("TempDir"); // Create the directory only if it does not already exist. if (di.Exists == false) di.Create(); // Create a subdirectory in the directory just created. DirectoryInfo dis = di.CreateSubdirectory("SubDir"); // Get a reference to the parent directory of the subdirectory you just made. DirectoryInfo parentDir = dis.Parent; Console.WriteLine("The parent directory of '{0}' is '{1}'", dis.Name, parentDir.Name); // Delete the parent directory. di.Delete(true); } }
using namespace System; using namespace System::IO; int main() { // Make a reference to a directory. DirectoryInfo^ di = gcnew DirectoryInfo( "TempDir" ); // Create the directory only if it does not already exist. if ( !di->Exists ) di->Create(); // Create a subdirectory in the directory just created. DirectoryInfo^ dis = di->CreateSubdirectory( "SubDir" ); // Get a reference to the parent directory of the subdirectory you just made. DirectoryInfo^ parentDir = dis->Parent; Console::WriteLine( "The parent directory of '{0}' is '{1}'", dis->Name, parentDir->Name ); // Delete the parent directory. di->Delete( true ); }
import System.*; import System.IO.*; public class MoveToTest { public static void main(String[] args) { // Make a reference to a directory. DirectoryInfo di = new DirectoryInfo("TempDir"); // Create the directory only if it does not already exist. if (di.get_Exists() == false) { di.Create(); } // Create a subdirectory in the directory just created. DirectoryInfo dis = di.CreateSubdirectory("SubDir"); // Get a reference to the parent directory of the // subdirectory you just made. DirectoryInfo parentDir = dis.get_Parent(); Console.WriteLine("The parent directory of '{0}' is '{1}'", dis.get_Name(), parentDir.get_Name()); // Delete the parent directory. di.Delete(true); } //main } //MoveToTest
import System; import System.IO; public class MoveToTest { public static function Main() { // Make a reference to a directory. var di : DirectoryInfo = new DirectoryInfo("TempDir"); // Create the directory only if it does not already exist. if (di.Exists == false) di.Create(); // Create a subdirectory in the directory just created. var dis : DirectoryInfo = di.CreateSubdirectory("SubDir"); // Get a reference to the parent directory of the subdirectory you just made. var parentDir : DirectoryInfo = dis.Parent; Console.WriteLine("The parent directory of '{0}' is '{1}'", dis.Name, parentDir.Name); // Delete the parent directory. di.Delete(true); } } MoveToTest.Main();


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.Parent プロパティのページへのリンク