다음을 통해 공유


FileSystemInfo 클래스

FileInfoDirectoryInfo 개체에 대한 기본 클래스를 제공합니다.

네임스페이스: System.IO
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public MustInherit Class FileSystemInfo
    Inherits MarshalByRefObject
    Implements ISerializable
‘사용 방법
Dim instance As FileSystemInfo
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public abstract class FileSystemInfo : MarshalByRefObject, ISerializable
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class FileSystemInfo abstract : public MarshalByRefObject, ISerializable
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public abstract class FileSystemInfo extends MarshalByRefObject implements ISerializable
SerializableAttribute 
ComVisibleAttribute(true) 
public abstract class FileSystemInfo extends MarshalByRefObject implements ISerializable

설명

FileSystemInfo 클래스에는 파일과 디렉터리를 조작할 때 공통적으로 사용되는 메서드가 포함됩니다. FileSystemInfo 개체는 파일이나 디렉터리를 나타낼 수 있으므로, FileInfo 또는 DirectoryInfo 개체에 대한 기본 클래스로 사용될 수 있습니다. 많은 파일과 디렉터리를 구문 분석하는 경우 이 기본 클래스를 사용합니다.

처음으로 호출될 때 FileSystemInfoRefresh를 호출하고 캐시된 정보를 API에 반환하여 특성 등을 가져옵니다. 다음에 호출할 때 Refresh를 호출하여 정보의 최신 복사본을 얻어야 합니다.

파생 클래스는 FileIOPermissionAccess 열거형에서 AllAccess 권한을 가진 경우에만 FileSystemInfo에서 상속할 수 있습니다.

경로가 적용되는 멤버에서 경로는 파일이나 디렉터리를 참조할 수 있습니다. 또한 지정된 경로는 서버와 공유 이름의 상대 경로나 UNC(Universal Naming Convention) 경로를 나타낼 수 있습니다. 예를 들어, 다음과 같은 경로를 사용할 수 있습니다.

  • C#의 "c:\\MyDir\\MyFile.txt" 또는 Visual Basic의 "c:\MyDir\MyFile.txt"

  • C#의 "c:\\MyDir" 또는 Visual Basic의 "c:\MyDir"

  • C#의 "MyDir\\MySubdir" 또는 Visual Basic의 "MyDir\MySubDir"

  • C#의 "\\\\MyServer\\MyShare" 또는 Visual Basic의 "\\MyServer\MyShare"

다음 표에서는 일반적인 예 또는 관련된 I/O 작업의 예를 보여 줍니다.

수행 작업

참조 항목

텍스트 파일을 만듭니다.

방법: 파일에 텍스트 쓰기

텍스트 파일에 씁니다.

방법: 파일에 텍스트 쓰기

텍스트 파일에서 읽습니다.

방법: 파일의 텍스트 읽기

파일에 텍스트를 추가합니다.

방법: 로그 파일 열기 및 추가

File.AppendText

FileInfo.AppendText

파일을 삭제합니다.

File.Delete

FileInfo.Delete

파일 이름을 바꾸거나 이동합니다.

File.Move

FileInfo.MoveTo

파일을 복사합니다.

File.Copy

FileInfo.CopyTo

디렉터리를 만듭니다.

Directory.CreateDirectory

System.IO.DirectoryInfo

하위 디렉터리를 만듭니다.

CreateSubdirectory

디렉터리 이름을 바꾸거나 이동합니다.

Directory.Move

DirectoryInfo.MoveTo

디렉터리를 삭제합니다.

Directory.Delete

DirectoryInfo.Delete

디렉터리를 복사합니다.

Directory

디렉터리의 파일을 크기순으로 정렬합니다.

GetFileSystemInfos

디렉터리의 파일을 참조하십시오.

Name

디렉터리의 하위 디렉터리를 참조하십시오.

GetDirectories

GetDirectories

디렉터리의 전체 하위 디렉터리에 있는 모든 파일을 참조하십시오.

GetFileSystemInfos

디렉터리의 크기를 찾습니다.

Directory

파일 크기를 가져옵니다.

FileInfo.Length

파일 특성을 가져옵니다.

File.GetAttributes

파일의 특성을 설정합니다.

File.SetAttributes

파일이 있는지 여부를 확인합니다.

File.Exists

이진 파일에서 읽습니다.

방법: 새로 만든 데이터 파일 읽기 및 쓰기

이진 파일에 씁니다.

방법: 새로 만든 데이터 파일 읽기 및 쓰기

확장명을 검색합니다.

Path.GetExtension

파일의 정규화된 경로를 검색합니다.

Path.GetFullPath

경로에서 파일 이름 및 확장명을 검색합니다.

Path.GetFileName

확장명을 변경합니다.

Path.ChangeExtension

예제

다음 예제에서는 모든 파일과 디렉터리를 반복하면서 각 항목에 대한 정보를 쿼리하는 방법을 보여 줍니다.

Imports System.IO
Module Module1

    Sub Main()
        ' Loop through all the immediate subdirectories of C.
        For Each entry As String In Directory.GetDirectories("C:\")
            DisplayFileSystemInfoAttributes(New DirectoryInfo(entry))
        Next

        ' Loop through all the files in C.
        For Each entry As String In Directory.GetFiles("C:\")
            DisplayFileSystemInfoAttributes(New FileInfo(entry))
        Next
    End Sub

    Sub DisplayFileSystemInfoAttributes(ByVal fsi As IO.FileSystemInfo)
        ' Assume that this entry is a file.
        Dim entryType As String = "File"

        ' Determine if this entry is really a directory.
        If (fsi.Attributes And FileAttributes.Directory) <> 0 Then
            entryType = "Directory"
        End If

        ' Show this entry's type, name, and creation date.
        Console.WriteLine("{0} entry {1} was created on {2:D}", _
            entryType, fsi.FullName, fsi.CreationTime)
    End Sub
End Module

' Output will vary based on contents of drive C.
' 
' Directory entry C:\Documents and Settings was created on Tuesday, November 25, 2003
' Directory entry C:\Inetpub was created on Monday, January 12, 2004
' Directory entry C:\Program Files was created on Tuesday, November 25, 2003
' Directory entry C:\RECYCLER was created on Tuesday, November 25, 2003
' Directory entry C:\System Volume Information was created on Tuesday, November 2, 2003
' Directory entry C:\WINDOWS was created on Tuesday, November 25, 2003
' File entry C:\IO.SYS was created on Tuesday, November 25, 2003
' File entry C:\MSDOS.SYS was created on Tuesday, November 25, 2003
' File entry C:\pagefile.sys was created on Saturday, December 27, 2003

.NET Framework 보안

  • FileIOPermission  연관된 열거형: Unrestricted 보안 동작: 상속 요청 이 클래스에서 상속하기 위한 권한입니다.

상속 계층 구조

System.Object
   System.MarshalByRefObject
    System.IO.FileSystemInfo
       System.IO.DirectoryInfo
       System.IO.FileInfo

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

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에서 지원

참고 항목

참조

FileSystemInfo 멤버
System.IO 네임스페이스

기타 리소스

파일 및 스트림 I/O
방법: 파일의 텍스트 읽기
방법: 파일에 텍스트 쓰기
기본 파일 I/O
방법: 새로 만든 데이터 파일 읽기 및 쓰기