FileInfo.Directory 속성
부모 디렉터리의 인스턴스를 가져옵니다.
네임스페이스: System.IO
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
Public ReadOnly Property Directory As DirectoryInfo
‘사용 방법
Dim instance As FileInfo
Dim value As DirectoryInfo
value = instance.Directory
public DirectoryInfo Directory { get; }
public:
property DirectoryInfo^ Directory {
DirectoryInfo^ get ();
}
/** @property */
public DirectoryInfo get_Directory ()
public function get Directory () : DirectoryInfo
속성 값
이 파일의 부모 디렉터리를 나타내는 DirectoryInfo 개체입니다.
예외
예외 형식 | 조건 |
---|---|
지정된 경로가 유효하지 않은 경우(예: 매핑되지 않은 드라이브의 경로를 지정한 경우) |
|
호출자에게 필요한 권한이 없는 경우 |
설명
부모 디렉터리를 문자열로서 가져오려면 DirectoryName 속성을 사용합니다.
다음 표에서는 일반적인 예 또는 관련된 I/O 작업의 예를 보여 줍니다.
수행 작업 |
참조 항목 |
---|---|
디렉터리를 복사합니다. |
|
디렉터리 이름을 바꾸거나 이동합니다. |
|
디렉터리를 삭제합니다. |
|
디렉터리를 만듭니다. |
Directory |
하위 디렉터리를 만듭니다. |
|
디렉터리의 파일을 참조하십시오. |
|
디렉터리의 하위 디렉터리를 참조하십시오. |
|
디렉터리의 전체 하위 디렉터리에 있는 모든 파일을 참조하십시오. |
|
디렉터리의 크기를 찾습니다. |
Directory |
파일이 있는지 여부를 확인합니다. |
|
디렉터리가 있는지 여부를 확인합니다. |
예제
다음 예제에서는 파일을 열거나 만든 다음 전체 경로를 결정하고 해당 디렉터리의 전체 내용을 확인하여 표시합니다.
Imports System
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 'Main
End Class 'DirectoryTest
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);
}
}
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 );
}
}
import System.*;
import System.IO.*;
public class DirectoryTest
{
public static void main(String[] args)
{
// 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.get_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.get_FullName());
// Print the names of all the files and subdirectories of
// that directory.
for (int iCtr = 0; iCtr < fsi.length; iCtr++) {
FileSystemInfo info = (FileSystemInfo)fsi.get_Item(iCtr);
Console.WriteLine(info.get_Name());
}
} //main
} //DirectoryTest
import System;
import System.IO;
public class DirectoryTest {
public static function Main() : void {
// Open an existing file, or create a new one.
var fi : FileInfo = new FileInfo("temp.txt");
// Determine the full path of the file just created.
var di : DirectoryInfo = fi.Directory;
// Figure out what other entries are in that directory.
var fsi : FileSystemInfo[] = 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.
for (var i : int in fsi)
Console.WriteLine(fsi[i].Name);
}
}
DirectoryTest.Main();
.NET Framework 보안
- FileIOPermission 파일을 읽는 데 필요한 권한입니다. 연관된 열거형: FileIOPermissionAccess.Read
플랫폼
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에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원
참고 항목
참조
FileInfo 클래스
FileInfo 멤버
System.IO 네임스페이스