GetFileInfo Method


GetFileInfo Method

Location

My.Computer.FileSystem.GetFileInfo

Syntax

     Dim result As System.IO.FileInfo = _        My.Computer.FileSystem.GetFileInfo(path) 


path (required; String)

The path to the file to be examined

Description

The GetFileInfo method returns a System.IO.FileInfo object for the indicated file.

Public Members

The returned System.IO.FileInfo object includes the following notable public members.

Member

Description

Attributes

Property. Gets or sets the attributes, using the System.IO.FileAttributes enumeration.

CopyTo

Method. Copies the file to a new location.

Create

Method. Creates a new file and opens it for writing.

Delete

Method. Deletes the file.

Directory

Property. The immediate directory of the file.

DirectoryName

Property. The full path of the directory containing the file.

Exists

Property. Indicates whether the file exists (true) or not (False).

FullName

Property. The full path to the file.

IsReadOnly

Property. Indicates whether the file is read only (true) or not (False).

Length

Property. The size of the file in bytes.

MoveTo

Method. Moves the file to a new location.

Name

Property. The name of the file without its full path.

Open

Method. Opens the file for reading or writing.


Usage at a Glance

  • An exception is thrown if the path parameter is missing or invalid.

  • An exception is thrown if the user lacks sufficient file-access privileges.

  • If the indicated file does not exist, this function may complete successfully with no exception thrown. However, an exception will be thrown when accessing most members of the returned object. Use the Exists property to test for the file if unsure of its existence.

Example

The following example reports a file's size.

     Public Sub ShowFileSize(filePath As String)        Dim theFile As System.IO.FileInfo        theFile = My.Computer.FileSystem.GetFileInfo(filePath)        If (theFile.Exists = True) Then           MsgBox("'" & filePath & "' does not exist.")        Else           MsgBox("'" & filePath & "' size: " & _              theFile.Length & "bytes")        End If     End Sub 

Related Framework Entries

  • Microsoft.VisualBasic.MyServices.FileSystemProxy.GetFileInfo Method

  • Microsoft.VisualBasic.FileIO.FileSystem.GetFileInfo Method

  • System.IO.FileInfo Class

See Also

CurrentDirectory Property, Drives Property, FileSystem Object, FindInFiles Method, GetDirectories Method, GetDirectoryInfo Method, GetDriveInfo Method, GetFiles Method, GetTempFileName Method




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net