ChDrive (statement)

Syntax

ChDrive DriveLetter$

Description

Changes the default drive to the specified drive.

Comments

Only the first character of DriveLetter$ is used.

DriveLetter$ is not case-sensitive.

If DriveLetter$ is empty, then the current drive is not changed.

Example

This example allows the user to select a new current drive and uses ChDrive to make their choice the new current drive.

Const crlf$ = Chr$(13) + Chr$(10)

Sub Main()

  Dim d()
  old$ = FileParse$(CurDir,1)
  DiskDrives d
Again:
  r = SelectBox("Available Drives","Select new current drive:",d)
  On Error Goto Error_Trap
  If r <> -1 Then ChDrive d®
  MsgBox "Old Current Drive: " & old$ & crlf & "New Current Drive: " & CurDir
  End
Error_Trap:
  MsgBox Error(err)
  Resume Again
End Sub

See Also

ChDir (statement); CurDir, CurDir$ (functions); Dir, Dir$ (functions); MkDir (statement); RmDir (statement); DiskDrives (statement).

More information

C