FileAttr Function

傳回使用 Open 陳述式開啟的檔案的存取模式或檔案存取號碼。檔案存取號碼取決於作業系統 (OSH = 作業系統標示元)。

評註圖示

如果您使用的是 32 位元作業系統,則無法使用 FileAttr 函式來確定檔案存取號碼。


另請參閱:Open

語法

FileAttr (FileNumber As Integer, Attribute As Integer)

傳回值類型

整型

參數:

FileNumber:使用 Open 陳述式所開啟檔案的號碼。

Attribute:整數表示式,用於指示所要傳回的檔案資訊的類型。可能是以下的值:

1: FileAttr 函式指示檔案的存取模式。

2: FileAttr 函式傳回作業系統的檔案存取號碼。

如果您將參數屬性指定為 1,則採用以下傳回值:

1 - INPUT (開啟檔案用於輸入)

2 - OUTPUT (開啟檔案用於匯出)

4 - RANDOM (開啟檔案用於隨機存取)

8 - APPEND (開啟檔案用於新增)

32 - BINARY (以二進制模式開啟檔案)。

錯誤代碼:

5 無效的程序呼叫

52 錯誤的檔案名稱或檔案編號

示例:

Sub ExampleFileAttr

Dim iNumber As Integer

Dim sLine As String

Dim aFile As String

    aFile = "c:\data.txt"

    iNumber = Freefile

    Open aFile For Output As #iNumber

    Print #iNumber, "This is a line of text"

    MsgBox FileAttr(#iNumber, 1 ),0,"Access mode"

    MsgBox FileAttr(#iNumber, 2 ),0,"File attribute"

    Close #iNumber

End Sub