FileSystem.GetFileInfo Method (String)

 
System_CAPS_noteNote

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

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
)

Parameters

file
Type: System.String

Name and path of the file.

Return Value

Type: System.IO.FileInfo

FileInfo object for the specified file

Exception Condition
ArgumentException

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

ArgumentNullException

file is Nothing or an empty string.

NotSupportedException

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

PathTooLongException

The path is too long.

SecurityException

The user lacks necessary permissions.

UnauthorizedAccessException

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.

To

See

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 & ".")

FileIOPermission

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

.NET Framework
Available since 2.0
Return to top
Show: