新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Const FILE_ATTRIBUTE_READONLY = &H1
Const FILE_ATTRIBUTE_HIDE = &H2
Const FILE_ATTRIBUTE_ARCHIVE = &H20
Const FILE_ATTRIBUTE_SYSTEM = &H4
Const FILE_ATTRIBUTE_DIRECTORY = &H10
Const FILE_ATTRIBUTE_NORMAL = &H80
Private Sub Command1_Click()
Dim InputFileName As String
InputFileName = App.Path & "\manongku.txt"
If (GetFileAttributes(InputFileName) And _
FILE_ATTRIBUTE_READONLY) Then
MsgBox "只读" '只读
End If
If (GetFileAttributes(InputFileName) And _
FILE_ATTRIBUTE_HIDE) Then
MsgBox "隐藏" '隐藏
End If
If (GetFileAttributes(InputFileName) And _
FILE_ATTRIBUTE_ARCHIVE) Then
MsgBox "存档" '存档
End If
If (GetFileAttributes(InputFileName) And _
FILE_ATTRIBUTE_SYSTEM) Then
MsgBox "系统" '系统
End If
If (GetFileAttributes(InputFileName) And _
FILE_ATTRIBUTE_DIRECTORY) Then
MsgBox "文件夹" '系统
Else
MsgBox "文件" '文件
End If
End Sub
在当前目录放一个manongku.txt然后运行程序。