Windows Dev Center

The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

File.GetAttributes Method

Gets the FileAttributes of the file on the path.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)

Public Shared Function GetAttributes ( _
	path As String _
) As FileAttributes


Type: System.String

The path to the file.

Return Value

Type: System.IO.FileAttributes
The FileAttributes of the file on the path.


path is empty, contains only white spaces, or contains invalid characters.


The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.


path is in an invalid format.


path represents a file and is invalid, such as being on an unmapped drive, or the file cannot be found.


path represents a directory and is invalid, such as being on an unmapped drive, or the directory cannot be found.


This file is being used by another process.


The caller does not have the required permission.

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see GetCurrentDirectory.

For a list of common I/O tasks, see Common I/O Tasks.

The following example demonstrates the GetAttributes and SetAttributes methods by applying the Archive and Hidden attributes to a file.

Imports System
Imports System.IO
Imports System.Text

Public Class Test
    Public Shared Sub Main()
        Dim path As String = "c:\temp\MyTest.txt" 

        ' Create the file if it does not exist. 
        If File.Exists(path) = False Then
        End If 

        Dim attributes As FileAttributes
        attributes = File.GetAttributes(path)

        If (attributes And FileAttributes.Hidden) = FileAttributes.Hidden Then 
            ' Show the file.
            attributes = RemoveAttribute(attributes, FileAttributes.Hidden)
            File.SetAttributes(path, attributes)
            Console.WriteLine("The {0} file is no longer hidden.", path)
            ' Hide the file.
            File.SetAttributes(path, File.GetAttributes(path) Or FileAttributes.Hidden)
            Console.WriteLine("The {0} file is now hidden.", path)
        End If 
    End Sub 

    Public Shared Function RemoveAttribute(ByVal attributes As FileAttributes, ByVal attributesToRemove As FileAttributes) As FileAttributes
        Return attributes And (Not attributesToRemove)
    End Function 
End Class

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

© 2015 Microsoft