About getting a local disk drive letter

Source: Internet
Author: User
About getting a local disk drive letter
There are four basic functions: getlogicaldrives, getlogicaldrivestrings, getdrivetype, and getvolumeinformation. The fifth is setvolumelabel. If you want to, you can use it to set the volume label.
The first function, getlogicaldrives, returns a DWORD bitmask value to inform the drive letter. "0" indicates drive a, "1" indicates drive B, and so on.
10110 10001 11000 00000 00000 00
This message indicates that there are drives a, c, d, f, J, K, and l in my computer.
The second function, getlogicaldrivestrings, returns an important string representing all drive letters. Each drive letter has a D:/(followed by a '/') format. Here, D indicates the drive letter. Each string has an empty (null) Terminator and two null characters at the end.
Getdrivetype returns a code, such as 2 representing a soft drive, 3 representing a hard drive, and 5 representing a CD-ROM drive.

1. getlogicaldrivestrings Method
Tchar Buf [100];
DWORD Len = getlogicaldrivestrings (sizeof (BUF)/sizeof (tchar), Buf );
The name indicates that getlogicaldrivestrings is the character form of the drive letter.
This function stores all drive letters in the Buf. The format is as follows:
"C:/<null> D:/<null> E:/<null>"
That is, the drive letter is separated by null, And the last drive letter is followed by two null
Therefore, you can extract a single drive letter from the Buf as follows:
For (cstring strdisks, tchar * s = Buf; * s; S + = _ tcslen (s) + 1)
{
Lpctstr sdrivepath = s; // a single drive letter
Strdisks + = sdrivepath;
Strdisks + = "";
}
At first, I don't know why tchar is used. I am afraid of using an error. Check msdn and get this sentence.
# Define char tchar; Khan ~~~

2. getlogicaldrives Method
DWORD dwdrives;
Char;
Cstring drivename;
Dwdrives = getlogicaldrives ();
A = 'a ';
While (dwdrives> 0)
{
If (dwdrives % 2 = 1)
{
Drivename. Format ("% C", );
Gettreectrl (). insertitem (drivename, m_nimageclose,
M_nimageopen, tvi_root, tvi_last );
}
A ++;
Dwdrives/= 2;
}
The getlogicaldrives function returns a DWORD Value with four 32-bit bytes. Each bit represents a drive letter. For example, bit0 represents a disk. However, because there are only 26 letters, a maximum of 26 drive letters can be returned, however, it is generally enough.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.