Platform SDK: Files and I/O

Enumerating Unique Volume Names

The following sample demonstrates how to obtain the unique volume name for a specified volume name; for example, "c:\".

This sample uses the GetVolumeNameForVolumeMountPoint function.

#define _WIN32_WINNT 0x0500

#include <windows.h>
#include <stdio.h>


#define BUFSIZE 1024   // ample space for our string buffer

int
main(int argc, char *argv[])
{
   BOOL bFlag;
   char Buf[BUFSIZE];          // temporary buffer for volume name
   char Drive[] = "c:\\";      // template drive specifier
   int i;                      // generic loop counter

   // Walk through legal drive letters, skipping floppies.
   for (i = 'c'; i < 'z';  i++ ) 
   {
      // Stamp the drive for the appropriate letter.
      Drive[0] = (char)i;

      bFlag = GetVolumeNameForVolumeMountPoint(
                 Drive, // input volume mount point or directory
                   Buf, // output volume name buffer
                BUFSIZE // size of volume name buffer
              );

      if (bFlag) 
      {
         printf ("The ID of drive %s is \"%s\"\n", Drive, Buf);
      }
   }
}