Export (0) Print
Expand All

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

The My.Computer.FileSystem.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!")
        MsgBox("File is not hidden!")
    End If

See Also

Community Additions

© 2015 Microsoft