GetDriveInfo Method


GetDriveInfo Method

Location

My.Computer.FileSystem.GetDriveInfo

Syntax

     Dim result As System.IO.DriveInfo = _        My.Computer.FileSystem.GetDriveInfo(drive) 


drive (required; String)

The letter of the drive to be examined. The supplied string is normally just the single-character drive letter. You can supply an absolute path as long as it begins with a drive letter; only the first letter of the string will be examined.

Description

The GetDriveInfo method returns a System.IO.DriveInfo object for the indicated drive.

Public Members

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

Member

Description

AvailableFreeSpace

Property. The available free space on the drive, in bytes, possibly limited by in-effect quotas.

DriveFormat

Property. The name of the format structure used on the drive, such as "NTFS" or "FAT32."

DriveType

Property. The type of drive, from the System.IO.DriveType enumeration.

IsReady

Property. Indicates whether the drive is ready for use (true) or not (False). This is useful for removable media drives, such as DVD drives.

Name

Property. The name of the drive, "C:" for example.

RootDirectory

Property. The root directory of the drive as a System.IO.DirectoryInfo object.

TotalFreeSpace

Property. The available free space on the drive in bytes.

TotalSize

Property. The total size of the drive in bytes, including both free and used portions of the drive.

VolumeLabel

Property. A short, friendly name for this drive.


The DriveType property uses one of the following System.IO.DriveType enumeration values.

Value

Description

CDRom

A CD-ROM device

Fixed

A fixed disk, such as an internal hard disk

Network

A nonlocal drive found on the network

NoRootDirectory

A drive with no root directory

Ram

A RAM disk

Removable

A drive with removable media

Unknown

Unknown device


Usage at a Glance

  • An exception is thrown if the drive parameter is missing or invalid. You can supply an absolute path as the argument to the GetDriveInfo method, but the first letter of that path must be a drive letter.

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

Example

The following example displays the amount of free space on the C drive.

     Dim cDrive As System.IO.DriveInfo     cDrive = My.Computer.FileSystem.GetDriveInfo("C:\")     MsgBox("Free space on the C drive: " & Format( _        cDrive.TotalFreeSpace / (1024 * 1024), "0.00") & " MB") 

Related Framework Entries

  • Microsoft.VisualBasic.MyServices.FileSystemProxy.GetDriveInfo Method

  • Microsoft.VisualBasic.FileIO.FileSystem.GetDriveInfo Method

  • System.IO.DriveInfo Class

See Also

CurrentDirectory Property, Drives Property, FileSystem Object, FindInFiles Method, GetDirectories Method, GetDirectoryInfo Method, GetFileInfo 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