This documentation is archived and is not being maintained.

ChDrive Function 

Changes the current drive.

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



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.

Exception type Error number Condition



Invalid drive is specified, or drive is unavailable.

See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.

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.

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.

This function is not supported.

Namespace: Microsoft.VisualBasic

Module: FileSystem

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)