Export (0) Print
Expand All

FileSystem.GetFileInfo Method

Returns a FileInfo object for the specified file.

Namespace:  Microsoft.VisualBasic.FileIO
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static FileInfo GetFileInfo(
	string file


Type: System.String

Name and path of the file.

Return Value

Type: System.IO.FileInfo
FileInfo object for the specified file


The path name is malformed. For example, it contains invalid characters or is only white space. The file name has a trailing slash mark.


file is Nothing or an empty string.


The path contains a colon in the middle of the string.


The path is too long.


The user lacks necessary permissions.


The user lacks ACL (access control list) access to the file.

An exception is not thrown if the file does not exist; rather, it will be thrown the first time the object's properties are accessed.

The following table lists an example of a task involving the My.Computer.FileSystem.GetFileInfo method.



Determine a file's name and path

How to: Parse File Paths in Visual Basic

This example retrieves a System.IO.FileInfo object for the file MyLogFile.log and uses it to report the file's full name, last access time, and length.

Dim information = My.Computer.FileSystem.GetFileInfo("C:\MyLogFile.log")
MsgBox("The file's full name is " & information.FullName & ".")
MsgBox("Last access time is " & information.LastAccessTime & ".")
MsgBox("The length is " & information.Length & ".")

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft