FileInfo.Directory Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets an instance of the parent directory.

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

Public ReadOnly Property Directory As DirectoryInfo

Property Value

Type: System.IO.DirectoryInfo

A DirectoryInfo object representing the parent directory of this file.

Exception Condition

The specified path is invalid, such as being on an unmapped drive.


The caller does not have the required permission.

To get the parent directory as a string, use the DirectoryName property.

The following example opens or creates a file, determines its full path, and determines and displays the full contents of the directory.

Imports System
Imports System.IO

Public Class DirectoryTest

    Public Shared Sub Main()
        ' Open an existing file, or create a new one.
        Dim fi As New FileInfo("temp.txt")

        ' Determine the full path of the file just created.
        Dim di As DirectoryInfo = fi.Directory

        ' Figure out what other entries are in that directory.
        Dim fsi As FileSystemInfo() = di.GetFileSystemInfos()

        ' Print the names of all the files and subdirectories of that directory.
        Console.WriteLine("The directory '{0}' contains the following files and directories:", di.FullName)
        Dim info As FileSystemInfo
        For Each info In fsi
        Next info
    End Sub 'Main
End Class 'DirectoryTest

'This code produces output similar to the following; 
'results may vary based on the computer/file structure/etc.:
'The directory 'C:\Visual Studio 2005\release' contains the following files 
'and directories:


for reading files. Associated enumeration: FileIOPermissionAccess.Read

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top