About   -   Contact   -   Purchase   -   Search   -   What's New

Get Volume Information
I was building a new explorer component that mimics the interface of the Windows explorer application. In order to show a list of Drives I needed to get the name of the Drive. The following API call gets the volume name as well as the serial number.

Create an NVO add the following local external function:

function long GetVolumeInformationA( ref string ls_RootPath, &
   ref string ls_VolName, long ll_VolLen, ref string ls_volserial, &
   long ll_maxcomplen, long ll_systemflags, &
   ref string ls_SystemName,&
   long ll_SystemLen ) Library 'kernel32'

Then add a function called GetVolumeName which accepts a string and returns a string and add the following code:

// Call the API function to get the volume
// label from a drive letter
String ls_Volume
String ls_Drive, ls_FileSys, ls_Flags, ls_Serial
Long ll_Max, ll_Flags, ll_RC, ll_FileSys
Long ll_Volume

ls_Drive = as_Volume
ls_Volume = Space(32)
ls_FileSys = Space(32)
ls_Serial = Space(32)
ll_Volume = Len( ls_Volume )
ll_FileSys = Len( ls_Filesys )

ll_RC = GetVolumeInformationA( ls_Drive, ls_Volume, ll_Volume, &
	ls_Serial, ll_Max, ll_Flags, ls_FileSys, ll_FileSys )

IF ll_RC = 0 THEN 
	ls_Volume = ''
	ls_Volume = Trim( ls_Volume )

RETURN ls_Volume

Call the function passing the drive you want the volume name for. For example C:\


Top of Page

Legal Notice

Ken Howe 2011