VB3 How to Get Current Drive's Free Disk Space in VB 3.0

ID: Q113590

3.00 WINDOWS

The information in this article applies to:

- Microsoft Visual Basic programming system for Windows, version 3.0

SUMMARY

This article shows how to find out how much free disk space is available on the current drive by calling the DiskSpaceFree function found in SETUPKIT.DLL.

The SETUPKIT.DLL file ships with the Setup kit in Visual Basic version 3.0. The DiskSpaceFree function is useful for finding the total space available on a drive. If you use the DiskSpaceFree function in your Visual Basic program, you need to distribute the SETUPKIT.DLL file to your customers.

MORE INFORMATION

There are also other functions in the SETUPKIT.DLL that may be useful. You can use the AllocUnit function to get the disk Allocation unit for the current drive and the SetTime function to set the destination file's date and time to the source file's date and time. For the declarations for these functions and others, please see the following article in the Microsoft Knowledge Base:

ARTICLE-ID: Q109290

TITLE     : Popular Windows API Functions Used from Visual Basic 3.0

Examples of using these SETUPKIT.DLL functions can also be found in the \VB\SETUPKIT\SETUP1\SETUP1.MAK project which is part of the SetupWizard.

Steps to Finding Out How Much Free Space Is Available on Drive C:

1. Start a new project in Visual Basic. Form1 is created by default.

2. Add one Label control (Label1) and one Command button (Command1)

   to Form1.

3. Using the following table as a guide, set the properties of the
   controls you added in step 2.

   Control Name   Property       New Value
   --------------------------------------------------------------
   Command1       Caption        Press for Free Space on Drive C:
   Label1         AutoSize       True

4. Place the following code in the (general) (declarations) section
   of Form1:

   Declare Function DiskSpaceFree Lib "SETUPKIT.DLL" () As Long

5. Place the following code in the Command1 Click event procedure of
   Form1:

   Sub Command1_Click ()
     Dim free_space& ' Holds number of bytes returned from DiskSpaceFree().

     ChDrive "c:"    ' Change to the drive you want to test.
     free_space& = DiskSpaceFree()

     ' Enter the following two lines as one, single line:
     Label1.Caption = "The total free space on drive C: =  " &
        Str$(free_space&) & " bytes"

   End Sub

6. From the Run menu, choose Start (ALT, R, S), or press the F5 key to run
   the program. Click the Command1 button to view the free disk space on
   drive C:.

KBCategory: KBSubcategory: APrgOther Additional reference words: 3.00
Keywords          : kbcode 
Version           : 3.00
Platform          : WINDOWS

Last Reviewed: May 23, 1998