ChDrive Function

Changes the current drive.

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

Parameters

  • 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

Exception type

Error number

Condition

IOException

68

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.

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.

Smart Device Developer Notes

This function is not supported.

Requirements

Namespace:Microsoft.VisualBasic

**Module:**FileSystem

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

See Also

Reference

ChDir Function

CurDir Function

MkDir Function

RmDir Function

IOException

Other Resources

File, Directory, and Drive Properties in Visual Basic