FILEATTR

FILEATTR(filenumber, returntype)

Returns the file mode of the specified open file (Long).


filenumberThe number of the file (Integer).
returntypeThe number indicating the type of information to return (Integer):
1 = Returns a value indicating the file mode (32 bit systems) (default)
2 = Returns an operating system file handler (16 bit systems)

REMARKS
* The value returned can be one of the following:
* 1 = Input
* 2 = Output
* 4 = Random
* 8 = Append
* 32 = Binary
* If "filenumber" is not valid, then a run-time error will be generated.
* This function returns the file mode for files opened using the Open statement.
* Can be used to determine the current attributes of an open file.
* You can use the CLOSE statement to close a text file.
* You can use the FILEDATETIME function to return the date and time a file was created or last modified.
* You can use the GETATTR function to return the attributes of a file or directory.
* You can use the OPEN statement to open a text file.
* The equivalent .NET function is [[Microsoft.VisualBasic.FileSystem.FileAttr]]
* For the Microsoft documentation refer to learn.microsoft.com

Dim lfileno As Long 
Dim lmode As Long

lfileno = 1
Open "C:\Temp\mytext.txt" For Input As lfileno
lmode = FileAttr(lfileno, 1)
Debug.Print lmode '1 for Input
Close lfileno

lfileno = 2
Open "C:\Temp\mytext.txt" For Output As lfileno
lmode = FileAttr(lfileno, 1)
Debug.Print lmode '2 for Output
Close lfileno

lfileno = 3
Open "C:\Temp\mytext.txt" For Append As lfileno
lmode = FileAttr(lfileno, 1)
Debug.Print lmode '8 for Append
Close lfileno

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top