chdrive

File Manipulation Functions

Switches to another drive on a Windows operating system.

int  chdrive( int drive); 

drive The name of a drive.

chdrive changes the current working drive to be drive, an integer representing the new drive. (1 = A, 2 = B, etc.)

Return Values

The chdrive function returns zero on success and (-1) for failure.

Example

The following example uses chdrive to move to all available drives on the file system. It saves the original drive in curdrive, so it can be restored later.

    int ch, drive, curdrive;

    static char path[1024];

    // Save current drive letter so it can be restored later

    curdrive = getdrive();

    // If we can switch to the drive, it exists

    lr_output_message ("Available drives are:");

    for (drive = 1; drive <= 26; drive++)

    if (!chdrive(drive))

        lr_output_message ("%c: ", drive + 'A' - 1);

        chdrive(curdrive); // Restore original drive

Example: Output:
Action.c(10): Available drives are:
Action.c(14): C:
Action.c(14): D:
Action.c(14): G:
Action.c(14): L:
Action.c(14): R:
Action.c(14): Z: