_chdrive
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at _chdrive.
Changes the current working drive.
This API cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported with /ZW. |
int _chdrive( int drive );
Parameters
drive
An integer from 1 through 26 that specifies the current working drive (1=A, 2=B, and so forth).
Zero (0) if the current working drive was changed successfully; otherwise, -1.
If drive is not in the range from 1 through 26, the invalid-parameter handler is invoked as described in Parameter Validation. If execution is allowed to continue, the _chdrive function returns -1, errno is set to EACCES, and _doserrno is set to ERROR_INVALID_DRIVE.
The _chdrive function is not thread-safe because it depends on the SetCurrentDirectory function, which is itself not thread-safe. To use _chdrive safely in a multi-threaded application, you must provide your own thread synchronization. For more information, go to MSDN Library and then search for SetCurrentDirectory.
The _chdrive function changes only the current working drive; _chdir changes the current working directory.
| Routine | Required header |
|---|---|
| _chdrive | <direct.h> |
For more information, see Compatibility.
See the example for _getdrive.
System::Environment::CurrentDirectory
Directory Control
_chdir, _wchdir
_fullpath, _wfullpath
_getcwd, _wgetcwd
_getdrive
_mkdir, _wmkdir
_rmdir, _wrmdir
system, _wsystem