DISCOVER
×

How to Get Folder Size in VB6

Updated July 19, 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.

Cite this Article A tool to create a citation to reference this article Cite this Article

About the Author

Jim Campbell has been a computer engineer for over five years. He excels in hardware repair, computer programming and troubleshooting, and software design. He is currently attending Florida Atlantic University, pursuing a master's degree in computer and electrical engineering and fine-tuning his technical writing abilities.