FileInfo.Directory 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
부모 디렉터리의 인스턴스를 가져옵니다.
public:
property System::IO::DirectoryInfo ^ Directory { System::IO::DirectoryInfo ^ get(); };
public System.IO.DirectoryInfo Directory { get; }
public System.IO.DirectoryInfo? Directory { get; }
member this.Directory : System.IO.DirectoryInfo
Public ReadOnly Property Directory As DirectoryInfo
속성 값
이 파일의 부모 디렉터리를 나타내는 DirectoryInfo 개체입니다.
예외
지정된 경로가 잘못되었습니다(예: 매핑되지 않은 드라이브에 있음).
호출자에게 필요한 권한이 없는 경우
예제
다음 예제에서는 파일을 열거나 만들고, 전체 경로를 결정하고, 디렉터리의 전체 내용을 결정하고 표시합니다.
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 .
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET