We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

My.Computer.FileSystem.GetDirectoryInfo Method

Visual Studio 2008

Returns a DirectoryInfo object for the specified path.

' Usage
Dim value As System.IO.DirectoryInfo = My.Computer.FileSystem.GetDirectoryInfo(directory)
' Declaration
Public Function GetDirectoryInfo( _
   ByVal directory As String _
) As System.IO.DirectoryInfo


String. Path of directory. Required.

The following conditions may cause an exception:

  • The directory path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; or it is a device path (starts with \\.\) (ArgumentException).

  • The directory path is not valid because it is Nothing (ArgumentNullException).

  • The directory path exceeds the system-defined maximum length (PathTooLongException).

  • A file or directory name in the directory path contains a colon (:) or is in an invalid format (NotSupportedException).

  • The user lacks necessary permissions to view the directory path (SecurityException).

If the directory does not exist, an exception is not thrown until the first time a property on the DirectoryInfo object is accessed.

The following table lists examples of tasks involving the My.Computer.FileSystem.GetDirectoryInfo method.



Determine when a directory was created

How to: Determine a Directory's Creation Time in Visual Basic

Determine whether a directory is read-only

How to: Determine if a Directory is Read-Only in Visual Basic

This example gets a DirectoryInfo object for the directory C:\Documents and Settings and displays the directory's creation time, last access time, and last write time.

Dim getInfo As System.IO.DirectoryInfo
getInfo = My.Computer.FileSystem.GetDirectoryInfo _
MsgBox("The directory was created at " & getInfo.CreationTime)
MsgBox("The directory was last accessed at " & getInfo.LastAccessTime)
MsgBox("The directory was last written to at " & getInfo.LastWriteTime)

Namespace: Microsoft.VisualBasic.MyServices

Class: FileSystemProxy (provides access to FileSystem)

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Availability by Project Type

Project type


Windows Application


Class Library


Console Application


Windows Control Library


Web Control Library


Windows Service


Web Site


The following permission may be necessary:




Controls the ability to access files and folders. Associated enumeration: Unrestricted.

For more information, see Code Access Security and Requesting Permissions.