FileAttr 函数
返回 Open 语句打开的文件的访问模式或文件访问编号。文件访问编号取决于操作系统(OSH = 操作系统句柄)。
如果您使用的是 32 位操作系统,则不能使用 FileAttr 函数来确定文件访问编号。
请参阅:Open
语法:
FileAttr (FileNumber As Integer, Attribute As Integer)
返回值:
整数
参数:
FileNumber:使用 Open 语句打开的文件编号。
Attribute:表示要返回的文件信息类型的整数表达式,其值可以是:
1:FileAttr 函数指示文件的访问模式。
2: FileAttr 函数返回操作系统的文件访问编号。
如果您将参数属性指定为 1,则可以应用以下返回值:
1 - INPUT(打开文件进行输入)
1 - OUTPUT(打开文件进行输出)
4 - RANDOM(打开文件进行随机访问)
8 - APPEND(打开文件进行附加)
32 - BINARY(以二进制模式打开文件)。
示例:
Sub ExampleFileAttr
Dim iNumber As Integer
Dim sLine As String
Dim aFile As String
aFile = "c:\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