Udostępnij za pośrednictwem


My.Computer.FileSystem.GetFileInfo Method

Returns a FileInfo object for the specified file.

' Usage
Dim value As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(file)
' Declaration
Public Function GetFileInfo( _
   ByVal file As String _
) As System.IO.FileInfo

Parameters

  • file
    String. Name and path of the file. Required.

Return Value

FileInfo

Exceptions

The following conditions may cause an exception:

Remarks

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.

Tasks

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

To

See

To get information about a file

How to: Get Information About a File in Visual Basic

Determine a file's name and path

How to: Parse File Paths in Visual Basic

Example

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 As System.IO.FileInfo
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 & ".")

Requirements

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

Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

Yes

Windows Service

Yes

Web Site

Yes

Permissions

The following permission may be necessary:

Permission

Description

FileIOPermission

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

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

See Also

Tasks

Walkthrough: Manipulating Files and Directories in Visual Basic

Reference

My.Computer.FileSystem Object

System.IO.FileInfo

FileSystem.GetFileInfo

Other Resources

File, Directory, and Drive Properties in Visual Basic