Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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!")
    Else
        MsgBox("File is not hidden!")
    End If
    
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.