Skip to content

DiskType

A console snippet that walks every drive letter and reports its type with GetDriveType.

Published Nov 1, 1996

A quick inventory of the machine's drives: loop A through Z, call GetDriveType on each root, and print the numeric type for anything that is not DRIVE_NO_ROOT_DIR. The comment block at the bottom lists the constants - removable (2), fixed (3), remote (4), CD-ROM (5), RAM disk (6) - so you can extend it to friendly names in a line or two. Use it when your software needs to know what kind of storage it is about to touch.

#include <Windows.H>
#include <Stdio.H>

//////////////////////////////////////////////////////////////////////

char xDrive2Check[5];
int xDrive;
int DriveLoop;

int main(void)
{
    DriveLoop = 65; // Drive A
    for(;;)
    {
        sprintf(xDrive2Check,"%c:/",DriveLoop);
        xDrive = GetDriveTypeA(xDrive2Check);
        if(xDrive != 1)
        {
            printf("Drive %s Is Of The %d Type\n",xDrive2Check,xDrive);
        }
        if(DriveLoop == 90)break; // Drive Z
        DriveLoop++;
    }
    return 0;
}

/*
    #define DRIVE_REMOVABLE 2
    #define DRIVE_FIXED 3
    #define DRIVE_REMOTE 4
    #define DRIVE_CDROM 5
    #define DRIVE_RAMDISK 6
    #define DRIVE_UNKNOWN 0
    #define DRIVE_NO_ROOT_DIR 1
*/
An unhandled error has occurred. Reload 🗙