_dos_setdrive

Description

Sets the default drive, using system call 0x0E.

#include <dos.h>

void _dos_setdrive( unsigned drive, unsigned *numdrives );

drive New default drive  
numdrives Total drives available  

Remarks

The _dos_setdrive routine uses system call 0x0E to set the current default drive to the drive argument: 1 = drive A, 2 = drive B, and so on. The numdrives argument indicates the total number of drives in the system. If this value is 4, for example, it does not mean the drives are designated A, B, C, and D; it means only that four drives are in the system.

Return Value

There is no return value. If an invalid drive number is passed, the function fails without indication. Use the _dos_getdrive routine to verify whether the desired drive has been set.

Compatibility

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:None

See Also

_dos_getdiskfree, _dos_getdrive

Example

/* DGDRIVE.C: This program prints the letter of the current drive,

* changes the default drive to A, then returns the number of disk drives.

*/

#include <stdio.h>

#include <dos.h>

void main( void )

{

unsigned olddrive, newdrive;

unsigned number_of_drives;

/* Print current default drive information */

_dos_getdrive( &olddrive );

printf( “The current drive is: %c\n”, 'A' + olddrive - 1 );

/* Set default drive to be drive A */

printf( “Changing default drive to A\n”);

_dos_setdrive( 1, &number_of_drives );

/* Get new default drive information and total number of drives */

_dos_getdrive( &newdrive );

printf( “The current drive is: %c\n”, 'A' + newdrive - 1 );

printf( “Number of logical drives: %d\n”, number_of_drives );

/* Restore default drive */

_dos_setdrive( olddrive, &number_of_drives );

}

Output

The current drive is: C

Changing default drive to A

The current drive is: A

Number of logical drives: 26