ChDir Statement

Named Arguments

No

Syntax

ChDir path

path

Use: Required

Data Type: String

Any expression capable of conversion to a Date.

Description

Changes the current working (default) directory.

Rules at a Glance

  • Path can be an absolute or relative reference.

  • On Windows systems, changing the default directory doesn't change the default drive; it changes only a particular drive's default directory.

Example

sNewDir = "c:\program files\my folder\"
ChDir sNewDir
...
ChDir ".." 'c:\program files is now the default directory.

Programming Tips and Gotchas

  • Remember that on the Apple Power Macintosh, the relative notation "::" moves to the next higher folder, whereas on Windows 95 and NT, the notation is "..".

  • On Windows systems, the relative notation "." represents the current directory.

  • On Windows systems, the relative notation ".." represents the parent of the current directory. If the root directory is the current directory, the statement:

    ChDir ".."

    doesn't change the current directory and doesn't produce a syntax error.

  • On the Apple Power Macintosh, ChDir changes both the default directory and the default drive.

  • On Windows systems, the current drive is unaffected by ChDir. For instance, if the current drive is C:\ and you issue the statement:

    ChDir "D:\MyFolder"

    the current directory on drive D: is changed to D:\MyFolder, but the current drive is still C:\.

  • If path isn't found, a trappable error, 76, "Path not found," is generated. However, if path refers to another machine on ...

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.