VB icon

Drive Info

Email
Submitted on: 8/31/2016 7:50:36 PM
By: Thomas1965  
Level: Beginner
User Rating: By 1 Users
Compatibility: C++ (general), Microsoft Visual C++, Borland C++
Views: 1482
 
     Shows a list of all the available drives and their types.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Drive Info
// Description:Shows a list of all the available drives and their types.
// By: Thomas1965
//**************************************

#include <iostream>
#include <cstring>
#include <windows.h>
using std::cout;
void ShowDriveInfo(PCSTR DriveInfo);
int main()
{
 const int BUF_SIZE = 128;
 char buffer[BUF_SIZE] = {0};
 
 GetLogicalDriveStringsA(BUF_SIZE-1, buffer);
 cout << "Drive info\n";
 cout << "==========\n\n";
 PSTR cp = buffer;
 while(*cp)
 {
ShowDriveInfo(cp);
cp += strlen(cp) + 1;
 }
 cout << "\n\n";
 system("pause");
 return EXIT_SUCCESS;
}
void ShowDriveInfo(PCSTR DriveInfo)
{
 cout << "Info for drive " << DriveInfo << "\t";
 switch (GetDriveTypeA(DriveInfo)) 
 {
case 0:
 cout << "Unknown drive type\n";
 break;
case 1:
 cout << "Drive does not exist\n";
 break;
case DRIVE_CDROM:
 cout << "CD ROM\n";
 break;
case DRIVE_FIXED:
 cout << "Hard disk\n";
 break;
case DRIVE_RAMDISK:
 cout << "Ram disk\n";
 break;
case DRIVE_REMOTE:
 cout << "Network drive\n";
 break;
case DRIVE_REMOVABLE:
 cout << "Floppy disk / Flash disk\n";
 break;
 }
}


Other 24 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

8/31/2016 8:37:17 PMBen

Nise code Tom as always, something else to add to my tips collection.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.