Freigeben über


DirectoryInfo.Parent-Eigenschaft

Ruft das übergeordnete Verzeichnis eines angegebenen Unterverzeichnisses ab.

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public ReadOnly Property Parent As DirectoryInfo
'Usage
Dim instance As DirectoryInfo
Dim value As DirectoryInfo

value = instance.Parent
public DirectoryInfo Parent { get; }
public:
property DirectoryInfo^ Parent {
    DirectoryInfo^ get ();
}
/** @property */
public DirectoryInfo get_Parent ()
public function get Parent () : DirectoryInfo

Eigenschaftenwert

Das übergeordnete Verzeichnis oder NULL (Nothing in Visual Basic), wenn der Pfad null ist oder der Dateipfad ein Stammverzeichnis angibt (z. B. "\", "C:" oder * "\\server\share").

Ausnahmen

Ausnahmetyp Bedingung

SecurityException

Der Aufrufer verfügt nicht über die erforderliche Berechtigung.

Hinweise

In der folgenden Tabelle sind Beispiele für andere typische oder verwandte E/A-Aufgaben aufgeführt.

Aufgabe

Beispiel in diesem Thema

Umbenennen oder Verschieben eines Verzeichnisses.

Directory.Move

DirectoryInfo.MoveTo

Löschen eines Verzeichnisses.

Directory.Delete

DirectoryInfo.Delete

Erstellen eines Verzeichnisses.

CreateDirectory

Directory

Erstellen eines Unterverzeichnisses.

CreateSubdirectory

Anzeigen der Dateien in einem Verzeichnis.

Name

Anzeigen der Unterverzeichnisse in einem Verzeichnis.

GetDirectories

GetDirectories

Anzeigen aller Dateien und Unterverzeichnisse in einem Verzeichnis.

GetFileSystemInfos

Ermitteln der Größe eines Verzeichnisses.

Directory

Bestimmen, ob eine Datei vorhanden ist.

Exists

Sortieren von Dateien in einem Verzeichnis nach Größe.

GetFileSystemInfos

Bestimmen, ob ein Verzeichnis vorhanden ist.

Exists

Beispiel

Das folgende Beispiel veranschaulicht das Verweisen auf das übergeordnete Verzeichnis eines angegebenen Verzeichnisses.

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();

.NET Framework-Sicherheit

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

DirectoryInfo-Klasse
DirectoryInfo-Member
System.IO-Namespace

Weitere Ressourcen

Datei- und Stream-E/A
Gewusst wie: Lesen aus einer Textdatei
Gewusst wie: Schreiben von Text in eine Datei