目录

# FileAttr 函数

返回 Open 语句打开的文件的访问模式或文件访问编号。文件访问编号取决于操作系统 (OSH = 操作系统句柄)。

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

请参阅: Open

### 语法:

      FileAttr (Channel As Integer, Attributes As Integer)

### 返回值:

整数

### 参数:

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 (打开文件进行输入)

1 - 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:\Users\ThisUser\data.txt"
        iNumber = Freefile
        Open aFile For Output As #iNumber
        Print #iNumber, "这是一行文本"
        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