_chdrive -- Change Current Working Drive

Format

#include <direct.h>
int _chdrive(int drive);

Language Level: Extension
_chdrive changes the current working drive to the drive specified. The drive variable is an integer value representing the number of the new working drive (A: is 1, B: is 2, and so on).

To change the default drive on OS/2, include <os2.h>, define INCL_DOSFILEMGR, and use DosSetDefaultDisk to pass the appropriate command to the operating system. You can also use DosQueryCurrentDisk to query the disk. For more information, see the Control Program Guide and Reference.

An alternative to this function, on Windows, is the Win32 SetCurrentDirectory system call. For more information, see the Win32 Programmer's Reference.

Return Value
_chdrive returns 0 if it is successful in changing the working drive. A return value of -1 indicates an error; _chdrive sets errno to EOS2ERR.

Example
This example uses _chdrive to change the current working drive to C:.

#include <direct.h>
#include <stdio.h>
int main(void)
{
   if (_chdrive(3))
      printf("Cannot change current working drive to 'C' drive.\n");
   else {
      printf("Current working drive changed to ");
      printf("'%c' drive.\n", ('A'+_getdrive()-1));
   }
   return 0;
   /*****************************************************************
      The output should be similar to:
      Current working drive changed to 'C' drive.
   *****************************************************************/
}



chdir -- Change Current Working Directory
_getcwd -- Get Path Name of Current Directory
_getdcwd -- Get Full Path Name of Current Directory
_getdrive -- Get Current Working Drive
mkdir -- Create New Directory
rmdir -- Remove Directory
<direct.h>