FileInfo.Directory FileInfo.Directory FileInfo.Directory FileInfo.Directory Property

Definition

Ruft eine Instanz des übergeordneten Verzeichnisses ab.Gets an instance of the parent directory.

public:
 property System::IO::DirectoryInfo ^ Directory { System::IO::DirectoryInfo ^ get(); };
public System.IO.DirectoryInfo Directory { get; }
member this.Directory : System.IO.DirectoryInfo
Public ReadOnly Property Directory As DirectoryInfo

Eigenschaftswert

Ein DirectoryInfo-Objekt, das das übergeordnete Verzeichnis dieser Datei darstellt.A DirectoryInfo object representing the parent directory of this file.

Ausnahmen

Der angegebene Pfad ist ungültig, z. B. befindet er sich auf einem nicht zugeordneten Laufwerk.The specified path is invalid, such as being on an unmapped drive.

Der Aufrufer verfügt nicht über die erforderliche Berechtigung.The caller does not have the required permission.

Beispiele

Im folgenden Beispiel wird eine Datei geöffnet oder erstellt, der vollständige Pfad bestimmt und der gesamte Inhalt des Verzeichnisses ermittelt und angezeigt.The following example opens or creates a file, determines its full path, and determines and displays the full contents of the directory.

using namespace System;
using namespace System::IO;
int main()
{
   
   // Open an existing file, or create a new one.
   FileInfo^ fi = gcnew FileInfo( "temp.txt" );
   
   // Determine the full path of the file just created.
   DirectoryInfo^ di = fi->Directory;
   
   // Figure out what other entries are in that directory.
   array<FileSystemInfo^>^fsi = di->GetFileSystemInfos();
   Console::WriteLine( "The directory '{0}' contains the following files and directories:", di->FullName );
   
   // Print the names of all the files and subdirectories of that directory.
   Collections::IEnumerator^ myEnum = fsi->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      FileSystemInfo^ info = safe_cast<FileSystemInfo^>(myEnum->Current);
      Console::WriteLine( info->Name );
   }
}
//This code produces output similar to the following; 
//results may vary based on the computer/file structure/etc.:
//
//The directory 'C:\Visual Studio 2005\release' contains the following files 
//and directories:
//fileinfodirectory.exe
//fileinfodirectory.pdb
//newTemp.txt
//
using System;
using System.IO;

public class DirectoryTest 
{
    public static void Main() 
    {

        // Open an existing file, or create a new one.
        FileInfo fi = new FileInfo("temp.txt");

        // Determine the full path of the file just created.
        DirectoryInfo di = fi.Directory;

        // Figure out what other entries are in that directory.
        FileSystemInfo[] fsi = di.GetFileSystemInfos();

        Console.WriteLine("The directory '{0}' contains the following files and directories:", di.FullName);

        // Print the names of all the files and subdirectories of that directory.
        foreach (FileSystemInfo info in fsi)
            Console.WriteLine(info.Name);
    }
}
//This code produces output similar to the following; 
//results may vary based on the computer/file structure/etc.:
//
//The directory 'C:\Visual Studio 2005\release' contains the following files 
//and directories:
//TempPE
//fileinfodirectory.exe
//fileinfodirectory.pdb
//newTemp.txt
//temp.txt

Imports System.IO

Public Class DirectoryTest

    Public Shared Sub Main()
        ' Open an existing file, or create a new one.
        Dim fi As New FileInfo("temp.txt")

        ' Determine the full path of the file just created.
        Dim di As DirectoryInfo = fi.Directory

        ' Figure out what other entries are in that directory.
        Dim fsi As FileSystemInfo() = di.GetFileSystemInfos()

        ' Print the names of all the files and subdirectories of that directory.
        Console.WriteLine("The directory '{0}' contains the following files and directories:", di.FullName)
        Dim info As FileSystemInfo
        For Each info In fsi
            Console.WriteLine(info.Name)
        Next info
    End Sub
End Class 'DirectoryTest

'This code produces output similar to the following; 
'results may vary based on the computer/file structure/etc.:
'
'The directory 'C:\Visual Studio 2005\release' contains the following files 
'and directories:
'TempPE
'fileinfodirectory.exe
'fileinfodirectory.pdb
'fileinfodirectory.Resources.resources
'fileinfodirectory.vbproj.GenerateResource.Cache
'fileinfodirectory.xml
'

Hinweise

Um das übergeordnete Verzeichnis als Zeichenfolge zu erhalten, DirectoryName verwenden Sie die-Eigenschaft.To get the parent directory as a string, use the DirectoryName property.

Sicherheit

FileIOPermission
zum Lesen von Dateien.for reading files. Zugehörige Enumeration:ReadAssociated enumeration: Read

Gilt für:

Siehe auch