tags:

views:

1816

answers:

3

Hi!

I want to enumerate all available drive letters (which aren't already taken) in Windows using VC++.

How can I do this?

+2  A: 

The GetLogicalDriveStrings Function is a good starting point.

VonC
+4  A: 

GetLogicalDriveStrings can get you just the list of currently used drive letters.

GetVolumeInformation can be used to get more information about a specific drive.

Alnitak
+6  A: 

::GetLogicalDrives() returns a list of available (read: used) drives as bits in a mask. This should include mapped network drives. Thus, you can simply walk the bits to find bits that are zero, meaning no drive is present. If in doubt, you can always call ::GetDriveType() with the drive letter + ":\" (":\\" in C code, or _T(":\\") in Unicode-aware terminology, of course), and that should return DRIVE_UNKNOWN or DRIVE_NO_ROOT_DIR if the drive is available.

JTeagle
yes, that's easier than GetLogicalDriveStrings!
Alnitak