Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Display drive letters

Posted on 1999-07-01
5
Medium Priority
?
168 Views
Last Modified: 2013-11-20
I've got a dialog based app. using VC++ 5.0.  I want to display a list of the available drives (no files or subdirectories).  I don't need anything too fancy.  Right now, I'm just trying to use a List Box populated with DlgDirList(), but I don't know what to use for the parent path for all of the drives.  I'm open to using something other than a list box.  
0
Comment
Question by:halen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 2

Accepted Solution

by:
cpopin earned 200 total points
ID: 1308637
Try something like this:

CString sDrive;
for (char drive = 'A'; drive <= 'Z'; ++drive) {
      sDrive.Format("%c:\\");
      if (GetDriveType(sDrive) != DRIVE_UNKNOWN) {
            sDrive.Format("%c");
            m_lbDrives.AddString(sDrive);
      }
}
0
 
LVL 2

Expert Comment

by:cpopin
ID: 1308638
...and if you'd like to see the same code w/o EE removing the indention:

CString sDrive;
for (char drive = 'A'; drive <= 'Z'; ++drive) {
    sDrive.Format("%c:\\");
    if (GetDriveType(sDrive) != DRIVE_UNKNOWN) {
        sDrive.Format("%c");
        m_lbDrives.AddString(sDrive);
    }
}
0
 
LVL 2

Expert Comment

by:cpopin
ID: 1308639
Oops, that doesn't work...try this:

    CString sDrive;
    DWORD dwDrives = GetLogicalDrives();
    for (char drive = 'A'; drive <= 'Z'; ++drive, dwDrives >>= 1) {
        if (dwDrives & 1) {
            sDrive.Format("%c", drive);
            m_lbDrives.AddString(sDrive);
        }
    }
0
 

Author Comment

by:halen
ID: 1308640
It wasn't quite as straight forward as I had hoped, but it wasn't an excessive amount of code and it accomplished what I wanted.
0
 
LVL 2

Expert Comment

by:cpopin
ID: 1308641
GetLogicalDrives() returns a bit value with one bit turned on for each of the 26 drive letters.  It's kind of lame, but efficient.

GetLogicalDriveStrings() is more straight forward because it gives you a list of null-terminated strings represending drive paths.  The list ends with a double null chararter, like this:

a:\<null>c:\<null>d:\<null><null>
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question