Home > Windows API > Type of disk drive?

Type of disk drive?

Any idea on how to know the type of a drive, i.e. whether it’s a removable drive or CD-ROM or a network drive and others. Yes! use GetDriveType( lpctszDrive ) which returns DRIVE_XXXX (drive type).

So I will write some functions just to demonstrate these features.

// Returns true if drive is invalid (hope so!)
bool IsDriveInvalid( LPCTSTR lpctszDrive )
{
  ASSERT( lpctszDrive );
  return ( GetDriveType( lpctszDrive ) == DRIVE_NO_ROOT_DIR );
}

// Returns true if we have a removable drive like floppy or USB drive
bool IsRemovableDrive( LPCTSTR lpctszDrive )
{
  ASSERT( lpctszDrive );
  return ( GetDriveType( lpctszDrive ) == DRIVE_REMOVABLE );
}

// Returns true if drive is a fixed drive like hard disk
bool IsFixedDrive( LPCTSTR lpctszDrive )
{
  ASSERT( lpctszDrive );
  return ( GetDriveType( lpctszDrive ) == DRIVE_FIXED );
}

// Returns true if drive is a network drive
bool IsNetworkDrive( LPCTSTR lpctszDrive )
{
  ASSERT( lpctszDrive );
  return ( GetDriveType( lpctszDrive ) == DRIVE_REMOTE );
}

// Returns true if drive is a cd rom
bool IsCDROMDrive( LPCTSTR lpctszDrive )
{
  ASSERT( lpctszDrive );
  return ( GetDriveType( lpctszDrive ) == DRIVE_CDROM );
}

// Returns true if drive is a ram disk
bool IsRAMDisk( LPCTSTR lpctszDrive )
{
  ASSERT( lpctszDrive );
  return ( GetDriveType( lpctszDrive ) == DRIVE_RAMDISK );
}
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: