Udostępnij za pośrednictwem


How to: Determine if a File is Hidden in Visual Basic

The GetFileInfo method can be used to get a FileInfo object, which contains information about the specified file, including a FileAttributes enumeration.

To determine if a file is hidden

  1. Get a FileInfo object for the file you wish to examine. This example gets a FileInfo object for the file Testfile.txt.

    Dim infoReader As System.IO.FileInfo
    infoReader = My.Computer.FileSystem.GetFileInfo("C:\testfile.txt")
    
  2. Get a FileAttributes object from the FileInfo object. This example gets FileAttributes from the FileInfo object.

    Dim attributeReader As System.IO.FileAttributes
    attributeReader = infoReader.Attributes
    
  3. Query FileAttributes to determine if the file is hidden. This example determines if the file is hidden and displays a result accordingly.

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

See Also

Tasks

How to: Determine a File's Attributes in Visual Basic

Reference

FileSystem

GetFileInfo

Other Resources

File, Directory, and Drive Properties in Visual Basic