Answer the question
In order to leave comments, you need to log in
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
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;
}
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 questionAsk a Question
731 491 924 answers to any question