共用方式為


FileSystemInfo 類別

定義

FileInfoDirectoryInfo 物件提供基底類別。

public ref class FileSystemInfo abstract
public ref class FileSystemInfo abstract : MarshalByRefObject, System::Runtime::Serialization::ISerializable
public abstract class FileSystemInfo
public abstract class FileSystemInfo : MarshalByRefObject, System.Runtime.Serialization.ISerializable
[System.Serializable]
public abstract class FileSystemInfo : MarshalByRefObject, System.Runtime.Serialization.ISerializable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class FileSystemInfo : MarshalByRefObject, System.Runtime.Serialization.ISerializable
type FileSystemInfo = class
type FileSystemInfo = class
    inherit MarshalByRefObject
    interface ISerializable
[<System.Serializable>]
type FileSystemInfo = class
    inherit MarshalByRefObject
    interface ISerializable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type FileSystemInfo = class
    inherit MarshalByRefObject
    interface ISerializable
Public MustInherit Class FileSystemInfo
Public MustInherit Class FileSystemInfo
Inherits MarshalByRefObject
Implements ISerializable
繼承
FileSystemInfo
繼承
FileSystemInfo
衍生
屬性
實作

範例

下列範例示範如何迴圈查看所有檔案和目錄,查詢每個專案的相關信息。

using namespace System;
using namespace System::IO;


namespace ConsoleApplication2
{
    public ref class Program
    {
    public:
        static void Main()
        {
            //  Loop through all the immediate subdirectories of C.
            for each (String^ entry in Directory::GetDirectories("C:\\"))
            {
                DisplayFileSystemInfoAttributes(gcnew DirectoryInfo(entry));
            }
            //  Loop through all the files in C.
            for each (String^ entry in Directory::GetFiles("C:\\"))
            {
                DisplayFileSystemInfoAttributes(gcnew FileInfo(entry));
            }
        }
        static void DisplayFileSystemInfoAttributes(FileSystemInfo^ fsi)
        {
            //  Assume that this entry is a file.
            String^ entryType = "File";

            // Determine if entry is really a directory
            if ((fsi->Attributes & FileAttributes::Directory) == FileAttributes::Directory)
            {
                entryType = "Directory";
            }
            //  Show this entry's type, name, and creation date.
            Console::WriteLine("{0} entry {1} was created on {2:D}", entryType, fsi->FullName, fsi->CreationTime);
        }
    };
};

int main()
{
    ConsoleApplication2::Program::Main();
}

 // 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
using System;
using System.IO;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            //  Loop through all the immediate subdirectories of C.
            foreach (string entry in Directory.GetDirectories(@"C:\"))
            {
                DisplayFileSystemInfoAttributes(new DirectoryInfo(entry));
            }
            //  Loop through all the files in C.
            foreach (string entry in Directory.GetFiles(@"C:\"))
            {
                DisplayFileSystemInfoAttributes(new FileInfo(entry));
            }
        }
        static void DisplayFileSystemInfoAttributes(FileSystemInfo fsi)
        {
            //  Assume that this entry is a file.
            string entryType = "File";

            // Determine if entry is really a directory
            if ((fsi.Attributes & FileAttributes.Directory) == FileAttributes.Directory )
            {
                entryType = "Directory";
            }
            //  Show this entry's type, name, and creation date.
            Console.WriteLine("{0} entry {1} was created on {2:D}", entryType, fsi.FullName, fsi.CreationTime);
        }
    }
}

 // 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
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) = FileAttributes.Directory 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

備註

類別 FileSystemInfo 包含檔案和目錄操作通用的方法。 FileSystemInfo物件可以代表檔案或目錄,因此做為 或 DirectoryInfo 對象的基礎FileInfo。 剖析許多檔案和目錄時,請使用這個基類。

只有在衍生類別具有列舉的 AllAccess 許可權時,衍生類別才能 FileSystemInfo 繼承自 FileIOPermissionAccess

在接受路徑的成員中,路徑可以參考檔案或只參考目錄。 指定的路徑也可以參考伺服器和共用名的相對路徑或通用命名慣例 (UNC) 路徑。 例如,下列所有都是可接受的路徑:

  • 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 工作的清單,請參閱 一般 I/O 工作

建構函式

FileSystemInfo()

初始化 FileSystemInfo 類別的新執行個體。

FileSystemInfo(SerializationInfo, StreamingContext)
已淘汰.

使用序列化資料,初始化 FileSystemInfo 類別的新執行個體。

欄位

FullPath

表示目錄或檔案的完整路徑。

OriginalPath

使用者指定的相對或絕對的原始路徑。

屬性

Attributes

取得或設定目前檔案或目錄的屬性。

CreationTime

取得或設定目前檔案或目錄的建立時間。

CreationTimeUtc

取得或設定目前檔案或目錄的建立時間,其格式為國際標準時間 (Coordinated Universal Time,UTC)。

Exists

取得值,指出檔案或目錄是否存在。

Extension

取得檔名的擴展名部分,包括前置點 . ,即使它是整個檔名,或是沒有擴展名則為空字串。

FullName

取得目錄或檔案的完整路徑。

LastAccessTime

取得或設定上次存取目前檔案或目錄的時間。

LastAccessTimeUtc

取得或設定目前檔案或目錄上次被存取的時間,其格式為 Coordinated Universal Time (UTC)。

LastWriteTime

取得或設定上次寫入目前檔案或目錄的時間。

LastWriteTimeUtc

取得或設定目前檔案或目錄上次被寫入的時間,其格式為 Coordinated Universal Time (UTC)。

LinkTarget

取得位於 中FullName之連結的目標路徑,如果這個FileSystemInfo實例不代表連結,則null為 。

Name

對於檔案,取得檔案的名稱。 對於目錄,如果有階層架構,則是取得階層架構中最後一個目錄的名稱。 否則,Name 屬性會取得目錄的名稱。

UnixFileMode

取得或設定目前檔案或目錄的 Unix 檔案模式。

方法

CreateAsSymbolicLink(String)

建立位於的 FullName 符號連結,指向指定的 pathToTarget

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Delete()

刪除檔案或目錄。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetObjectData(SerializationInfo, StreamingContext)
已淘汰.

以檔案名稱和其他例外狀況資訊設定 SerializationInfo 物件。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
Refresh()

重新整理物件的狀態。

ResolveLinkTarget(Boolean)

取得指定鏈接的目標。

ToString()

傳回原始路徑。 使用 FullNameName 屬性作為完整路徑或檔案/目錄名稱。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱