See Also Example
Changes the current default directory on a specified drive.
Syntax
ChDir path
Remarks
The argument path is a string expression This argument must contain fewer than 128 characters and has the following syntax:
[drive:] [ \ ]directory[\directory] . . .
The argument drive is an optional drive specification; the argument directory is a directory name. If you omit drive, ChDir changes the default directory on the current drive.
The ChDir statement works like the operating system command CHDIR, except that it cannot be abbreviated to CD like the system command. Like the operating system command CHDIR, the ChDir statement changes the default directory but not the default drive. For example, if the default drive is C, the following statement changes the default directory on drive D, but C remains the default drive:
ChDir "D:\TMP"
Use the CurDir[$] function to determine the current directory and the ChDrive statement to change the default drive.
ChDrive Statement
CurDir, CurDir$ Functions
Dir, Dir$ Functions
MkDir Statement
RmDir Statement
The example uses ChDir to change the default directory on the current drive. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim Answer, Msg, NL ' Declare variables.
NL = Chr(10) ' Define newline.
CurPath = CurDir ' Get current path.
ChDir "\"
Msg = "The current directory has been changed to "
Msg = Msg & CurDir & NL & NL & "Press OK to change back "
Msg = Msg & "to your previous default directory."
Answer = MsgBox(Msg) ' Get user response.
ChDir CurPath ' Change back to user default.
Msg = "Directory changed back to " & CurPath & "."
MsgBox Msg ' Display results.
End Sub