S
S
Sergey Polyntsev2014-09-26 20:50:18
Programming
Sergey Polyntsev, 2014-09-26 20:50:18

How to determine what disks are in the system?

Hello! Silly decision, but I want to write my own file manager. The question is how to determine which drives are connected to the system, and how can you distinguish, for example, hard drives, optical drives, or flash drives?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
OvLab, 2014-09-26
@OvLab

Since the OS is not specified in the question, I will write how this is done in Windows.
GetLogicalDrives - returns a 32-bit number, each set bit of which indicates the availability of the corresponding drive in the system: bit 0 - A, bit 1 - B, bit 2 - C, and so on.
GetDriveType(DiskName) - when passing a drive letter to the function, its type is returned:
0 DRIVE_UNKNOWN
1 DRIVE_NO_ROOT_DIR
2 DRIVE_REMOVABLE (replaceable)
3 DRIVE_FIXED
4 DRIVE_REMOTE (network)
5 DRIVE_CDROM
6 DRIVE_RAMDISK
For example:
void main()
{
if (GetDriveType("F:" )==DRIVE_CDROM)
cout << "CD" << endl;
}

A
AlexP11223, 2014-09-27
@AlexP11223

In Windows, you can easily get a lot of things through WMI. Win32_DiskDrive , for example.
msdn.microsoft.com/en-us/library/windows/desktop/a...
https://github.com/MKisilyov/MoreReports/blob/mast... - some C++ code examples (initialization, etc.) . and at the bottom getting data about disks).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question