EziData Solutions - Brisbane's Access Specialists
Working with Drives, Folders and Files Tutorials

Getting Information about your Folders

Just knowing the drive letters on your computer isn’t very exciting, but using this information to display a list of folders starts getting a little more useful. The GetFolder method of the FileSystemObject returns a Folder object, which contains a whole lot of useful information about the folder, including its name, size and a collection of subfolders.

You may on occasion need to display or work with a list of sub-folders located within a parent folder. Thankfully, as with finding out what Drives your computer has access to, working with fodlers is easy using the Folders property of the FileSystemObject.

'declare the starting or root folder – you could get this from the Drives

Dim strRoot As String

strRoot = "C:\"

'declare the variables for use with the Scripting library

Dim fso As New Scripting.FileSystemObject

Dim parent As Scripting.Folder

Dim children As Scripting.Folders

Dim child As Scripting.Folder


'get the folder from fso

Set parent = fso.GetFolder(strRoot)


'get the subfolders contained within the root folder

Set children = parent.SubFolders

'iterate through the subfolder under the root and display some data

For Each child In children

Debug.Print child.name

Next

Other Topics about Using the FileSystemObject

Getting Information About Your Drives

Getting Information About Your Files

Working with Text Files

Reading from Text Files