win_setd.cpp
上传用户:dq031136
上传日期:2022-08-08
资源大小:802k
文件大小:1k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. void main(void)
  5.  {
  6.     char szBuffer[MAX_PATH+100];
  7.     UINT nDrive, AvailDrive = 0;
  8.     int dwLogicalDrives = GetLogicalDrives();
  9.     DWORD Success;
  10.     printf("Number of logical drives: %dn", dwLogicalDrives);
  11.      for (nDrive = 0; nDrive < 32; nDrive++)
  12.        {
  13.         if (dwLogicalDrives & (1 << nDrive))
  14.           { // Is drive available?
  15.             AvailDrive++;
  16.             // Get disk information.
  17.             wsprintf(szBuffer, "%c:\", nDrive+'A', '');
  18.             // Print out information.
  19.            if(SetCurrentDirectory(szBuffer))
  20.               printf("%s Is Now Currentn", szBuffer);
  21.          else
  22.               printf("Could not set %s as the current driven", szBuffer);
  23.           }
  24.        }
  25.       printf("Number of drives available: %dn", AvailDrive);
  26.  }