Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))

ChDir Procedure

Class

Microsoft.VisualBasic.FileSystem

Syntax

ChDir(path)

path (required; String)

The path of the directory to set as the new default or "current" directory

Description

The ChDir procedure changes the current working (default) directory.

Usage at a Glance

  • path can be either an absolute path or a relative path from the current directory.

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

  • If the root of a drive is already the current directory, and you try to change to a parent directory (".."), no error occurs and the directory is not changed.

  • An error occurs if the specified path does not exist.

  • Networked drives can only be used with ChDir if they have been mapped to a local drive letter and that drive letter is used in path.

Example

ChDir("c:\My Documents\My Folder\") ChDir("..") ' Uses the current directory's parent

Version Differences

  • ChDir was a statement in VB 6; it is now a procedure (a method of the FileSystem class) and requires parentheses around the path argument.

  • Visual Basic 2005 includes a My.Computer.FileSystem.CurrentDirectory property that provides similar functionality.

See Also

ChDrive Procedure, CurDir Function

Категории