FileInfo.Directory 속성

정의

부모 디렉터리의 인스턴스를 가져옵니다.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

속성 값

이 파일의 부모 디렉터리를 나타내는 DirectoryInfo 개체입니다.A DirectoryInfo object representing the parent directory of this file.

예외

지정된 경로가 잘못되었습니다(예: 매핑되지 않은 드라이브에 있음).The specified path is invalid, such as being on an unmapped drive.

호출자에게 필요한 권한이 없는 경우The caller does not have the required permission.

예제

다음 예제에서는 또는 파일을 만듭니다, 그리고의 전체 경로 결정 하 고 결정 열리고 디렉터리의 전체 내용이 표시 됩니다.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

'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
'

설명

부모 디렉터리를 문자열로 가져오려면 DirectoryName 속성을 사용 합니다.To get the parent directory as a string, use the DirectoryName property.

보안

FileIOPermission
파일 읽기.for reading files. 연결 된 열거형: ReadAssociated enumeration: Read

적용 대상

추가 정보