WindowsAPI详解——GetDriveType 获得逻辑驱动器的类型

http://flyxxtt.blogbus.com/logs/43181576.html

函数原型:
UINT GetDriveType(LPCTSTR lpRootPathName)

参数lpRootPathName是根目录,如"C:\",一定要加上反斜杠。
如果给此参数传入NULL将返回程序当前目录的驱动器类型返回值所代表的类型

请看下面的例子。

使用例子:

wstring getDriveType( LPCTSTR lpRootPathName )
{
  wstring typename;
  unsigned int type = GetDriveType( _T( "C:\\" ) );       //得到C盘类型
  switch ( type )
  {
    case DRIVE_UNKNOWN:
      typename = _T( "未知类型" );
      break;
    case DRIVE_NO_ROOT_DIR:
      typename = _T( "无效的根路径" );
      break;
    case DRIVE_REMOVABLE:
      typename = _T( "可移动磁盘或软盘" );
      break;
    case DRIVE_FIXED:
      typename = _T( "本地硬盘" );
      break;
    case DRIVE_REMOTE:
      typename = _T( "网络磁盘" );
      break;
    case DRIVE_CDROM:
      typename = _T( "CD-ROM" );
      break;
    case DRIVE_RAMDISK:
      typename = _T( "RAM" );
      break;
    default:
      typename = _T( "未知类型" );
  }
  return typename;
}

 

你可能感兴趣的:(windows)