Visual Basic Language Reference  

ChDrive Function

Changes the current drive.

Public Overloads Sub ChDrive(ByVal Drive As { Char | String })

Parameter

Drive
Required. String expression that specifies an existing drive. If you supply a zero-length string (""), the current drive doesn't change. If the Drive argument is a multiple-character string, ChDrive uses only the first letter.

Exceptions/Errors

Exception type Error number Condition
IOException 68 Invalid drive is specified, or drive is unavailable.

Remarks

The ChDrive function requires unmanaged code permission, which may affect its execution in partial trust situations. For more information, see SecurityPermission Class and Code Access Permissions.

Example

This example uses the ChDrive function to change the current drive. The function throws an exception if the drive does not exist.

ChDrive("D")   ' Make "D" the current drive.

Requirements

Namespace: Microsoft.VisualBasic

Module: FileSystem

Assembly: Microsoft Visual Basic .NET Runtime (in MicrosoftVisualBasic.dll)

See Also

ChDir Function | CurDir Function | MkDir Function | RmDir Function | IOException Class