win_setd.cpp
Upload User: dq031136
Upload Date: 2022-08-08
Package Size: 802k
Code Size: 1k
Development Platform:

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.  }