Change Directory Method
The Change Directory method changes the default directory of a drive. It does not return a value. It does the following depending on how you use the arguments:
Include the drive argument. It changes the default directory on the current drive.
Include the first backslash in [\]directory\. It uses the path from the root directory.
Do not include the first backslash in [\]directory\. It changes to a directory that resides in the current directory.
The Change Directory method does not change the default drive. You can use the Change Drive method to change the default drive.
Format
ChDir [drive][[\]directory\]directory
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
drive |
The name of the drive that contains the desired default directory. You can use one of the following values:
A colon is not required. |
[\]directory\ |
The path. You can use one of the following values:
You can use this argument in the following situations:
|
directory |
The name of the directory that this method sets for the default directory, or a string expression that identifies this name. |
Example
The following example changes the current directory to C:\Windows:
Sub Button_Click
Dim newdir as String
newdir = "c:\Windows"
If CurDir <> newdir then
ChDir newdir
End If
End Sub