Contents

# FileAttr Function

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

If you use a 32-Bit operating system, you cannot use the FileAttr function to determine the file access number.

另請參閱：Open

### Syntax:

      FileAttr (Channel As Integer, Attributes As Integer)

### Return value:

整型

### Parameters:

Channel: The number of the file that was opened with the Open statement.

Attributes: Integer expression that indicates the type of file information that you want to return. The following values are possible:

1: FileAttr indicates the access mode of the file.

2: FileAttr returns the file access number of the operating system.

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

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

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

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

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

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

### 錯誤代碼：

5 無效的程序呼叫

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

### Example:

    Sub ExampleFileAttr
        Dim iNumber As Integer
        Dim sLine As String
        Dim aFile As String
        aFile = "C:\Users\ThisUser\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

相關主題

Close Statement

FreeFile Function

Open Statement

Print# Statement