Export (0) Print
Expand All

How to: Determine a File's Attributes 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.

This table shows the members of FileAttributes.

Member Description


The file's archive status. Applications use this attribute to mark files for backup or removal.


The file is compressed.


This member is not used at this time.


The file is a directory.


All of the data in the file is encrypted.


The file is hidden and will not be displayed in an ordinary directory listing.


The file has no other attributes set.


The file will not be indexed by the operating system's content indexing service.


The file is offline. The data in the file is not immediately available.


The file is read-only.


The file contains a reparse point, which is a block of user-defined data.


The file is a sparse file. Sparse files are usually large files containing data that is mostly zeroes.


The file is a system file. The file is part of the operating system or is used exclusively by the operating system.


The file is temporary. File systems attempt to keep all of the data in memory for quicker access, rather than flushing the data back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed.

To determine if a file is encrypted

  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. This example determines if the file is encrypted and displays a result accordingly.

    If (attributeReader And System.IO.FileAttributes.Encrypted) > 0 Then
        MsgBox("File is encrypted!")
        MsgBox("File is not encrypted!")
    End If

See Also

Community Additions

© 2015 Microsoft