You are currently offline, waiting for your internet to reconnect

How to Use the GetVolumeInformation API Call

This article was previously published under Q139547
The Win32API set offers a rich collection of features that were notavailable to previous versions of FoxPro for Windows. This article shows byexample how to call the Win32API GetVolumeInformation function.
The GetVolumeInformation function returns information about a file systemand volume whose root directory is specified in the call. While there areseveral common file systems (such as NTFS, FAT, and CDFS), new file systemsmay be in development that can affect things such as storage requirementsfor applications, so calling GetVolumeInformation may provide valuableinformation that you can use in your application. You can also use some ofthe information returned by this call to calculate disk space and filesizes. The following code shows how to declare and use this API call.

Code Sample

**---------------------------------------------------------------**** Program: Getvol.prg                                           **** Purpose: Demonstrates how to declare and use the Win32        ****          GetVolumeInformation API.                           ****---------------------------------------------------------------**PUBLIC lpRootPathName, ;        lpVolumeNameBuffer, ;        nVolumeNameSize, ;        lpVolumeSerialNumber, ;        lpMaximumComponentLength, ;        lpFileSystemFlags, ;        lpFileSystemNameBuffer, ;        nFileSystemNameSizelpRootPathName           = "E:\"      && Drive and directory pathlpVolumeNameBuffer       = SPACE(256) && lpVolumeName return buffernVolumeNameSize          = 256        && Size of/lpVolumeNameBufferlpVolumeSerialNumber     = 0          && lpVolumeSerialNumber bufferlpMaximumComponentLength = 256lpFileSystemFlags        = 0lpFileSystemNameBuffer   = SPACE(256)nFileSystemNameSize      = 256DECLARE INTEGER GetVolumeInformation IN Win32API AS GetVolInfo ;        STRING  @lpRootPathName, ;        STRING  @lpVolumeNameBuffer, ;        INTEGER nVolumeNameSize, ;        INTEGER @lpVolumeSerialNumber, ;        INTEGER @lpMaximumComponentLength, ;        INTEGER @lpFileSystemFlags, ;        STRING  @lpFileSystemNameBuffer, ;        INTEGER nFileSystemNameSizeRetVal=GetVolInfo(@lpRootPathName, @lpVolumeNameBuffer, ;                  nVolumeNameSize, @lpVolumeSerialNumber, ;                  @lpMaximumComponentLength, @lpFileSystemFlags, ;                  @lpFileSystemNameBuffer, nFileSystemNameSize)**---------------------------------------------------------------**** Return code values for file system flags. Return codes are    **** shown in parentheses.                                         ****---------------------------------------------------------------**** FS_CASE_SENSITIVE     If this flag is set, the file system    ****                       supports case-sensitive file names      ****                       (0001h).                                ****                                                               **** FS_CASE_IS_PRESERVED  If this flag is set, the file system    ****                       preserves the case of file names when   ****                       it places a name on disk (0002h).       ****                                                               **** FS_UNICODE_ON_DISK    If this flag is set, the file system    ****                       supports Unicode in file names as they  ****                       appear on disk (0004h).                 ****                                                               **** FS_PERSISTENT_ACLS    If this flag is set, the file system    ****                       preserves and enforces ACLs. For        ****                       example, NTFS preserves and enforces    ****                       ACLs, but HPFS and FAT do not (0008h)   ****                                                               **** FS_FILE_COMPRESSION   The file system supports file-based     ****                       compression (0010h)                     ****                                                               **** FS_VOL_IS_COMPRESSED  The specified volume is a compressed    ****                       volume; for example, a DoubleSpace      ****                       volume (8000h)                          ****---------------------------------------------------------------**** The following information is pertinent to several of the      **** listed flags:                                                 ****---------------------------------------------------------------**** The FS_VOL_IS_COMPRESSED flag is the only indicator of volume-**** based compression. The file system name is not altered to     **** indicate compression. This flag comes back set on a Double-   **** Space volume, for example. With volume-based compression, an  **** entire volume is either compressed or not compressed.         ****                                                               **** The FS_FILE_COMPRESSION flag indicates whether a file system  **** supports file-based compression. With file-based compression, **** individual files can be compressed or not compressed.         ****                                                               **** The FS_FILE_COMPRESSION and FS_VOL_IS_COMPRESSED flags are    **** mutually exclusive; both bits cannot come back set.           ****---------------------------------------------------------------**** Note that the return value can be a combination of the        **** individual return values. For example, a return value of 6    **** indicates that case is preserved (FS_CASE_IS_PRESERVED) and   **** the file system supports UNICODE in file names                **** (FS_UNICODE_ON_DISK).                                         ****---------------------------------------------------------------**DEFINE WINDOW ShowInfo FROM 0,0 TO 10,70 ;                       FLOAT CLOSE ;                       TITLE "Drive Information for " + ;                       ALLTRIM(lpRootPathName) ;                       FONT "Courier",10ACTIVATE WINDOW ShowInfoMOVE WINDOW ShowInfo CENTER**--------------------------------------------------------------**** Because several of the return values are padded with a null  **** terminator, you will need to strip off the null terminator   **** in order to get the correct value, which is what is done     **** using the LEFT, ALLTRIM, and LEN functions.                  ****--------------------------------------------------------------**@ 0,1 SAY "Drive & path name            : " + ;   ALLTRIM(lpRootPathName)@ 1,1 SAY "Volume name                  : " + ;   LEFT(ALLTRIM(lpVolumeNameBuffer),LEN(ALLTRIM(lpVolumeNameBuffer))-1)@ 2,1 SAY "Max #/chars in vol name      : " + ;   ALLTRIM(STR(nVolumeNameSize))@ 3,1 SAY "Volume Serial #              : " + ;   ALLTRIM(STR(lpVolumeSerialNumber))@ 4,1 SAY "Max #/chars in dir/file names: " + ;   ALLTRIM(STR(lpMaximumComponentLength))@ 5,1 SAY "File System Flags            : " + ;   ALLTRIM(STR(lpFileSystemFlags))@ 6,1 SAY "File System type             : " + ;   LEFT(ALLTRIM(lpFileSystemNameBuffer), ;   LEN(ALLTRIM(lpFileSystemNameBuffer))-1)@ 7,1 SAY "File Sys Name Size           : " + ;   ALLTRIM(STR(nFileSystemNameSize))** ----------------------------< End Code >-------------------------- **If this code is run on an NTFS partition, the following would be typicaloutput:Drive & Path name             : E:\ Volume name                   : ScratchMax #/chars in vol name       : 256Volume Serial #               : 484847074Max #/chars in dir/file names : 255File System Flags             : 31File System Type              : NTFSFile System Name Size         : 256The File System Flags value of 31 is a combination of the following filesystem attributes:Flag                      Hex Value   Decimal Value---------------------------------------------------FS_CASE_SENSITIVE             1             1FS_CASE_IS_PRESERVED          2             2FS_UNICODE_ON_DISK            4             4FS_PERSISTENT_ACLS            8             8FS_FILE_COMPRESSION          10            16---------------------------------------------------Total return value:                        31				
The value returned for the serial number is the decimal notation of thehexadecimal value displayed when you use a DIR command. In the informationshown previously in this article, the value that is displayed by the DIRcommand for this drive is 1CE6-2DE2 (hexadecimal), which corresponds to theserial number 484847074.

For additional information on this API function, please see search forGetVolumeInformation in the Win32API Help file. Note that this help file isavailable only on the compact disc version of Visual FoxPro; this help fileis not shipped with the disk version. For more information, please see thefollowing article in the Microsoft Knowledge Base:
139172 PRB: Visual FoxPro CD-ROM Compact Disc Includes Extra Files
For information about the DECLARE - DLL command, please refer to the VisualFoxPro Help file.
VFoxWin drive volume disk attributes

Article ID: 139547 - Last Review: 10/15/2003 20:07:46 - Revision: 2.1

  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 6.0 Professional Edition
  • kbcode KB139547