Applecore Pages on Microsoft Access

Finding the size of a folder

If you wish to find out the size of a folder from Access, it seems that the easiest way of doing this is to use the FileSystemObject.

In order to use this object, you will first need to set a reference to the Microsoft Scripting Runtime library, 'scrrun.dll'.

You can then use an Access function such as:

Function fFolderSpace(strFolderName As String) As Double
'   Function to return the size of a folder in bytes
'   Accepts:
'       A valid folder name, ideally terminated with "\"
'   Returns
'       The number of bytes a folder takes up, including all files and folders within it
'       If there is an error, for example no such folder exists, it returns -1

    On Error GoTo E_Handle
    Dim fso As New FileSystemObject
    Dim folder As Folder
    If Right(strFolderName, 1) <> "\" Then strFolderName = strFolderName & "\"
    Set folder = fso.GetFolder(strFolderName)
    fFolderSpace = folder.Size
fExit:
    Exit Function
E_Handle:
    Select Case Err.Number
        Case 76 ' Path not found
        Case Else
            MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
    End Select
    fFolderSpace = -1
    Resume fExit
End Function

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 14:58:06