如何:在 Visual Basic 中确定文件是否为隐藏文件

更新:2007 年 11 月

My.Computer.FileSystem.GetFileInfo 方法可用于获取包含有关指定文件的信息的 FileInfo 对象,包括 FileAttributes 枚举。

确定文件是否为隐藏的

  1. 获取要检查的文件的 FileInfo 对象。此示例获取文件 Testfile.txt 的 FileInfo 对象。

    Dim infoReader As System.IO.FileInfo
    infoReader = My.Computer.FileSystem.GetFileInfo("C:\testfile.txt")
    
  2. FileInfo 对象获取 FileAttributes 对象。此示例从 FileInfo 对象获取 FileAttributes 对象。

    Dim attributeReader As System.IO.FileAttributes
    attributeReader = infoReader.Attributes
    
  3. 查询 FileAttributes 以确定文件是否为隐藏的。此示例确定文件是否为隐藏的并显示相应的结果。

    If (attributeReader And System.IO.FileAttributes.Hidden) > 0 Then
        MsgBox("File is hidden!")
    Else
        MsgBox("File is not hidden!")
    End If
    

请参见

任务

如何:在 Visual Basic 中确定文件的属性

参考

My.Computer.FileSystem 对象

My.Computer.FileSystem 对象成员

My.Computer.FileSystem.GetFileInfo 方法

其他资源

文件、目录和驱动器属性 (Visual Basic)