O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

ChDir Procedure

Class

Microsoft.VisualBasic.FileSystem

Syntax

ChDir(path)
path (required; String)

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

Description

Changes the current working (default) directory.

Rules at a Glance

  • path can be an absolute or relative reference.

  • Changing the default directory does not change the default drive; it only changes a particular drive’s default directory.

Example

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

Programming Tips and Gotchas

  • The single dot (".") represents the current directory and the double dot ("..") represents the parent of the current directory. If the root directory is the current directory, the statement:

    ChDir("..")

    does not change the current directory and does not produce a syntax error.

  • If path is not found, or a FileNotFoundExeception exception, 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 directory for a particular drive.

VB.NET/VB 6 Differences

In VB.NET, ChDir is implemented as a procedure (a method of the FileSystem class). In VB 6, it ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required