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:
The path name is malformed. For example, it contains invalid characters or is only white space (ArgumentException).
The file name has a trailing slash mark (ArgumentException).
The file does not exist or is Nothing (ArgumentNullException).
The path contains a colon in the middle of the string (NotSupportedException).
The path is too long (PathTooLongException).
The user lacks necessary permissions (SecurityException).
The user lacks ACL (access control list) access to the file (UnauthorizedAccessException).
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 |
|
Determine a file's name and path |
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 |
---|---|
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
Microsoft.VisualBasic.FileIO.FileSystem.GetFileInfo(System.String)