#include <stdio.h>
#include <conio.h>
#include <direct.h>
#include <stdlib.h>
#include <ctype.h>void main( void )
{
   int ch, drive, curdrive;
   static char path[_MAX_PATH];   /* Save current drive. */
   curdrive = _getdrive();   printf( "Available drives are: \n" );   /* If we can switch to the drive, it exists. */
   for( drive = 1; drive <= 26; drive++ )
      if( !_chdrive( drive ) )
         printf( "%c: ", drive + 'A' - 1 );   while( 1 )
   {
      printf( "\nType drive letter to check or ESC to quit: " );
      ch = _getch();
      if( ch == 27 )
         break;
      if( isalpha( ch ) )
         _putch( ch );
      if( _getdcwd( toupper( ch ) - 'A' + 1, path, _MAX_PATH ) != NULL )
         printf( "\nCurrent directory on that drive is %s\n", path );
   }   /* Restore original drive.*/
   _chdrive( curdrive );
   printf( "\n" );
}

解决方案 »

  1.   

    API:
    SHGetSpecialFolderLocation      获得系统目录ID列表
    SHGetPathFromIDList             把系统目录ID列表转换为文件系统路径
      

  2.   

    char lpBuffer[MAX_PATH];
    ::GetLogicalDriveStrings(MAX_PATH, lpBuffer);
    lpBuffer中会包含所有的盘符每个盘符间好像是'\n'分开
      

  3.   

    GetLogicalDrives()不能得到所有的盘符,只能得到当前的盘符呀,怎么得到系统的所有盘符
      

  4.   

    ::GetLogicalDriveStrings(MAX_PATH,  lpBuffer);
      我有两 个盘符,但用它之后,只能显示一个盘符,是怎么会事???
      

  5.   

    GetLogicalDrives()可以得到所有盘符:
    它返回32位的值,每一位表示一个逻辑驱动器是否存在。
    如果有A盘,第0位置一,有C盘,第2位置一,明白了吗?