共用方式為


HOW TO:在 Visual Basic 中判斷檔案屬性

更新:2007 年 11 月

My.Computer.FileSystem.GetFileInfo 方法可以用於取得 FileInfo 物件,此物件會包含指定之檔案的相關資訊,包括 FileAttributes 列舉型別 (Enumeration)。

此表會顯示 FileAttributes 的成員。

成員

描述

Archive

檔案的封存狀態。應用程式會使用這個屬性,標記要備份或移除的檔案。

Compressed

檔案已壓縮。

Device

這個成員目前並未使用。

Directory

檔案是目錄。

Encrypted

檔案中的所有資料都已加密。

Hidden

檔案為隱藏的,因此不會顯示在一般目錄清單中。

Normal

檔案沒有其他屬性設定。

NotContentIndexed

作業系統的內容索引服務將不會編製檔案的索引。

Offline

檔案為離線狀態。無法立即使用檔案中的資料。

ReadOnly

檔案是唯讀的。

ReparsePoint

檔案包含了重新剖析點,這是使用者定義的資料區塊。

SparseFile

檔案是疏鬆檔案。疏鬆檔案通常是包含資料大部分為零的大型檔案。

System

檔案是系統檔案。檔案是作業系統的一部分,或由作業系統獨佔使用。

Temporary

檔案是暫存的。檔案系統會嘗試將所有資料保留在記憶體中以便更快速存取,而不是將資料清除回大型存放區。不再需要暫存檔案時,應用程式應盡快加以刪除。

若要判斷檔案是否加密

  1. 針對您要檢查的檔案,取得 FileInfo 物件。這個範例會取得檔案 Testfile.txt 的 FileInfo 物件。

    Dim infoReader As System.IO.FileInfo
    infoReader = My.Computer.FileSystem.GetFileInfo("C:\testfile.txt")
    
  2. FileInfo 物件取得 FileAttributes 物件。這個範例會從 FileInfo 物件取得 FileAttributes

    Dim attributeReader As System.IO.FileAttributes
    attributeReader = infoReader.Attributes
    
  3. 查詢 FileAttributes。這個範例會判斷檔案是否加密,並據此顯示結果。

    If (attributeReader And System.IO.FileAttributes.Encrypted) > 0 Then
        MsgBox("File is encrypted!")
    Else
        MsgBox("File is not encrypted!")
    End If
    

請參閱

工作

HOW TO:在 Visual Basic 中判斷檔案是否為隱藏

參考

FileAttributes

FileInfo

My.Computer.FileSystem 物件

My.Computer.FileSystem.GetFileInfo 方法

其他資源

Visual Basic 中的檔案、目錄和磁碟機屬性