ChDrive Procedure


ChDrive Procedure

Class

Microsoft.VisualBasic.FileSystem

Syntax

     ChDrive(drive) 


drive (required; String or Char)

The letter of the drive (A-Z) to set as the new default drive

Description

The ChDrive procedure changes the current working (default) disk drive.

Usage at a Glance

  • Only the first character of drive is considered. If a zero-length string is supplied, the drive is not changed.

  • The current directory is unaffected by the ChDrive procedure.

  • Since ChDrive only considers the first letter of the drive string, it is not valid to supply a UNC path (such as \\ServerName\ShareName).

  • Use the CurDir function to determine the current drive and directory.

Example

The following example implements one method of testing for a valid drive using the ChDrive procedure.

     Public Function IsAvailableDrive(newDrive As String) As Boolean        ' ----- Check for the existence of a logical drive.        Dim currentDrive As String        ' ----- Save the current setting.        On Error Resume Next        currentDrive = Microsoft.VisualBasic.Left(CurDir(  ), 1)        ' ----- Change to the proposed drive. If an error occurs,        '       then assume the drive doesn't exist.        Err.Clear(  )        ChDrive(newDrive)        If (Err.Number = 0) Then           IsAvailableDrive = True        Else           IsAvailableDrive = False        End If        ' ----- Restore the previous settings.        ChDrive(currentDrive)     End Function 

Version Differences

  • ChDrive was a statement in VB 6; it is now a procedure (a method of the FileSystem class) and requires parentheses around the drive argument.

  • Visual Basic 2005 includes a My.Computer.FileSystem.CurrentDirectory property that provides related functionality.

See Also

ChDrive Procedure, CurDir Function




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