Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
chdir
◄Summary► ◄Example► ◄Up► ◄Contents► ◄Index► ◄Back►
────────────────────────────────────────────────────────────────────────────
The chdir function changes the current working directory to the
directory specified by <dirname>. The <dirname> argument must
refer to an existing directory.
This function can change the current working directory on any
drive; it cannot change the default drive itself. For example, if
A: is the default drive and \BIN is the current working directory,
the following call changes the current working directory for
drive C:
chdir("c:\\temp");
Note that you must place two backslashes (\\) in a C string in
order to represent a single backslash (\). The backslash is the
escape character for C strings and therefore requires special
handling.
This function call has no apparent immediate effect. However, when
the _chdrive function is called to change the default drive to C:,
the current working directory becomes C:\TEMP.
In OS/2 protected mode, the current working directory is local to
a process rather than system-wide. When a process terminates, the
current working directory is restored to its original value. Under
DOS, the new directory set by the program becomes the new current
working directory.
Return Value
The chdir function returns a value of 0 if the working directory
is successfully changed. A return value of -1 indicates an error,
in which case errno is set to ENOENT, indicating that the
specified path name could not be found.
-♦-