Функция FileAttr

Возвращает режим доступа или номер доступа к файлу, открытому инструкцией Open. Номер доступа к файлу зависит от операционной системы (OSH = Operating System Handle).

Значок примечания

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)

Return value:

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 (файл открыт для записи)

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:\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

Пожалуйста, поддержите нас!