BUG: Drive Object Properties Are Incorrect on Large Drives (>2GB)

ID: Q225032


The information in this article applies to:


SYMPTOMS

The FreeSpace, TotalSize, or AvailableSpace properties of the File System object's Drive object return incorrect results.


CAUSE

This problem occurs when:

The reason that this problem occurs is that 2147483647 is the maximum value that can be stored in a 32-bit integer, a Visual Basic Long. The File System object does not take the possibility of larger values into account.


RESOLUTION

To work around this problem, use the Windows API function GetDiskFreeSpaceEx to return the total size, available space, and free space of a drive. For additional information about using the GetDiskFreeSpaceEx function, please see the following article in the Microsoft Knowledge Base:

Q225144 HOWTO: Use GetDiskFreeSpaceEx to Retrieve Drive Information


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new Visual Basic Standard EXE Project on a Windows 95/98 system. Form1 is created by default.


  2. On the Project menu, click References. Check Microsoft Scripting Run-time, and then click OK.


  3. Add the following code to the General Declarations section of Form1:


  4. 
    Private Sub Form_Click()
       Dim fso As New FileSystemObject
    
       With fso.Drives("C")
          Debug.Print "Total Size     : " & .TotalSize
          Debug.Print "Available Space: " & .AvailableSpace
          Debug.Print "Free Space     : " & .FreeSpace
       End With
    End Sub    
  5. Press the F5 key to run the program and click the Form.

    Results: The TotalSize, AvailableSpace, and FreeSpace properties are printed in the immediate pane, returning incorrect results if the expected return value exceeds two gigabytes.


Additional query words:


Keywords          : kbActiveX KbVBA kbVBp kbVBp500 kbVBp600 kbGrpDSO 
Version           : WINDOWS:5.0,6.0
Platform          : WINDOWS 
Issue type        : kbbug 

Last Reviewed: May 7, 1999