How to Get Folder Size in VB6

Written by jim campbell | 13/05/2017

Visual Basic 6 (VB6) contains a class named "FileSystemObject" that retrieves the name of a folder and returns the size of the folder contents using the "GetFolder.Size" function. The code lets you automate file creation and check for existing drive and folder space to ensure that the program does not crash.

Click the Windows "Start" button and select "All Programs." Click "Microsoft Visual Basic" in the program groups, and then click "Visual Basic" to open the software.

Click the "File" menu item, and then click "Open" to open a dialogue window. Click your Visual Basic project file name, and then click "Open" to load the code.

Double-click the VB6 form to load it in the designer. Right-click the opened form and click "View Code" to view the form's code in the editor.

Type the following code to retrieve the size of a folder:

Dim filesystem As FileSystemObject

Set filesystem = New FileSystemObject

GetFolderSize = filesystem.GetFolder("c:\windows").Size

Replace "C:\Windows" with the directory you want to view. The "GetFolderSize" variable contains the folder's size.

Click "Save" in the main VB6 toolbar. Click "Run" to execute the code in the VB6 debugger.

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.