Borland C++ reference

chdir

raw OCR

Changes current directory.

Defined in header <dir.h>

Syntax

#include <dir.h>
int chdir(const char *path);

Portability

DOSUNIXWindowsANSI CC++ only
■■■

Remarks

chdir causes the directory specified by path to become the current working directory, path must specify an existing directory.

A drive can also be specified in the path argument, such as chdir("a:\\BC")

but this changes only the current directory on that drive; it doesn't change the active drive.

Return value

Upon successful completion, chdir returns a value of 0. Otherwise, it returns a value of -1, and the global variable errno is set to

ENOENT Path or file name not found

See also

Example

Unclude  <stdio.h>
#include <stdlib.h>
#include <dir.h>

char old_dir[MAXDIR] ;
char new_dir[MAXDIR] ;

int main (void)
{
   if  (getcurdir(0, old_dir)) {
      perror ("getcurdir()") ;
      exit(l) ;
   }
   printf ("Current directory is: \\%s\n",  old_dir);
   if  (chdir("\\")) {
      perror ("chdir()");
      exit(l) ;
   }
   if  (getcurdir(0, new_dir)) {
      perror ("getcurdir() ");
      exit(l);
   }
   printf ("Current directory is now:  \\%s\n", new_dir);
   printf ("\nChanging back to orignal directory:  \\%s\n", old_dir) ;
   if (chdir (old_dir)) {
      perror ("chdir()");
      exit(l) ;
  - }
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.