Partager via


FileAttr Function 

Returns an enumeration representing the file mode for files opened using the FileOpen function.

The My.Computer.FileSystem Object gives you greater productivity and performance in file I/O operations than the FileAttr function. See My.Computer.FileSystem.GetFileInfo Method for more information.

Public Function FileAttr(ByVal FileNumber As Integer) As OpenMode

Parameters

  • FileNumber
    Required. Integer. Any valid file number.

Exceptions

Exception type Error number Condition

IOException

52

FileNumber does not exist.

IOException

54

File mode is invalid.

See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.

Return Value

The following enumeration values indicate the file access mode:

Value Mode

1

OpenMode.Input

2

OpenMode.Output

4

OpenMode.Random

8

OpenMode.Append

32

OpenMode.Binary

Remarks

This function returns an enumeration representing the file mode for files opened using the FileOpen function.

Example

This example uses the FileAttr function to return the file mode of an open file.

Dim mode As OpenMode
FileOpen(1, "c:\TESTFILE.TXT", OpenMode.Input)
mode = FileAttr(1)
MsgBox("The file mode is " & mode.ToString())
FileClose(1)

Smart Device Developer Notes

This function is not supported.

Requirements

Namespace: Microsoft.VisualBasic

Module: FileSystem

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

See Also

Reference

GetAttr Function
FileOpen Function
SetAttr Function
IOException Class

Other Resources

File, Directory, and Drive Properties in Visual Basic