ChDir Statement

Named Arguments


ChDir path

Use: Required

Data Type: String

The path of the directory to set as the new default directory. Description

Changes the current working (default) directory.

ChDir Statement


VB & VBA in a Nutshell: The Language, eMatter Edition Copyright © 2000 O'Reilly & Associates, Inc. All rights reserved.

• 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 & 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:

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 the network, error 75, "Path/ File access error," is generated.

• Although you can use a network path such as \\NTSERV1\d$\TestDir\ to change the current directory on the network admin share \\NTSERV1\d$, you can't access this drive using ChDrive without having the drive mapped to a drive letter, which makes using network paths with ChDir a little pointless!

• Use CurDir to determine the current default directory for a particular drive.

• If you are using VB6, you will find that the new File System objects offer much more flexibility than the intrinsic drive and directory statements.

See Also

ChDrive Statement, CurDir Function, MkDir Statement, Name Statement, RmDir Statement, File System Objects

154 Chapter 7 - The Language Reference

Was this article helpful?

+1 0

Post a comment